Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

10,484 questions

14,262 answers

573 users

How to use rounding math methods in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        System.out.println("1) " + Math.ceil(3.1));
        System.out.println("2) " + Math.ceil(3.0));
        System.out.println("3) " + Math.ceil(3.5));
        System.out.println("4) " + Math.ceil(3.6));
        System.out.println("5) " + Math.ceil(-3.0));
        System.out.println("6) " + Math.ceil(-3.1));
        System.out.println("7) " + Math.ceil(-3.5));
        System.out.println("8) " + Math.ceil(-3.6));
        
        System.out.println("9) " + Math.floor(3.1));
        System.out.println("10) " + Math.floor(3.0));
        System.out.println("11) " + Math.floor(3.5));
        System.out.println("12) " + Math.floor(3.6));
        System.out.println("13) " + Math.floor(-3.0));
        System.out.println("14) " + Math.floor(-3.1));        
        System.out.println("15) " + Math.floor(-3.5));        
        System.out.println("16) " + Math.floor(-3.6));
        
        System.out.println("17) " + Math.rint(3.0));
        System.out.println("18) " + Math.rint(3.1));
        System.out.println("19) " + Math.rint(3.5));
        System.out.println("20) " + Math.rint(3.6));
        System.out.println("21) " + Math.rint(-3.0));
        System.out.println("22) " + Math.rint(-3.1));
        System.out.println("23) " + Math.rint(-3.5));
        System.out.println("24) " + Math.rint(-3.6));
        
        System.out.println("25) " + Math.round(3.1));        
        System.out.println("26) " + Math.round(3.6f));
        System.out.println("27) " + Math.round(3.5));
        System.out.println("28) " + Math.round(3.6));
        System.out.println("29) " + Math.round(4.0));
        System.out.println("30) " + Math.round(-4.0f));
        System.out.println("31) " + Math.round(-3.1));
        System.out.println("32) " + Math.round(-3.5));
        System.out.println("33) " + Math.round(-3.6));
    }
}



/*
run:

1) 4.0
2) 3.0
3) 4.0
4) 4.0
5) -3.0
6) -3.0
7) -3.0
8) -3.0
9) 3.0
10) 3.0
11) 3.0
12) 3.0
13) -3.0
14) -4.0
15) -4.0
16) -4.0
17) 3.0
18) 3.0
19) 4.0
20) 4.0
21) -3.0
22) -3.0
23) -4.0
24) -4.0
25) 3
26) 4
27) 4
28) 4
29) 4
30) -4
31) -3
32) -3
33) -4

*/

 




answered Jun 11 by avibootz
...