» » Math.round() method in java

  • 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

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu