How to round double numbers using Math.round() method in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        System.out.println(Math.round(13000));

        System.out.println(Math.round(100.44));
        System.out.println(Math.round(100.55));
        System.out.println(Math.round(100.66));
        
        System.out.println(Math.round(100.4999));
        System.out.println(Math.round(100.5009));
        System.out.println(Math.round(100.6001));

        System.out.println(Math.round(-150.40099));
        System.out.println(Math.round(-150.50009));
        System.out.println(Math.round(-150.60001));

        System.out.println(Math.round(-13000));
    }
}
   
/*
      
run:

13000
100
101
101
100
101
101
-150
-151
-151
-13000
  
*/

 



answered Nov 9, 2016 by avibootz

Related questions

...