The Artima Developer Community
Sponsored Link

Java Buzz Forum
Math.round() method in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Math.round() method in java Posted: Apr 23, 2017 8:46 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Math.round() method in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • By using java.lang.math.round in java we will get crossest numbers.
  • If we pass double number with some decimal points it will returns closest integer or long  number. 
  • If we pass float number with some decimal points it will return closest integer or long number.
  • Lets see an example program on how to use math.random() method.
  • Math.random() method will returns closest int or long numbers.



Java program to round double number using math.random() method in java


  1. package com.mathrandommethod;
  2.  
  3. public class MathRandom {
  4.         /**
  5.          * Math.random() in java
  6.          * @author www.instanceofjava.com
  7.          */
  8.     public static void main(String[] args) {
  9.         
  10.           float float1 = 23.34f;
  11.           float float2 = 23.623f;
  12.           double double1 = 234.433;
  13.          double double2 = 234.654;
  14.  
  15.           System.out.println(Math.round(float1));
  16.           System.out.println(Math.round(float2)); 
  17.           System.out.println(Math.round(double1)); 
  18.           System.out.println(Math.round(double2));
  19.  }
  20.  
  21. }
Output:

  1. 23
  2. 24
  3. 234
  4. 235
java math random

Read: Math.round() method in java

Topic: Java example program to round double to 2 decimal places Previous Topic   Next Topic Topic: The news from Docker-land, plus, the money being fought over - Notebook

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use