How to round float 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(13f));

        System.out.println(Math.round(10.4f));
        System.out.println(Math.round(10.5f));
        System.out.println(Math.round(10.6f));

        System.out.println(Math.round(-15.4f));
        System.out.println(Math.round(-15.5f));
        System.out.println(Math.round(-15.6f));

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

13
10
11
11
-15
-15
-16
-13
  
*/

 



answered Nov 9, 2016 by avibootz

Related questions

...