How to round up to 2 decimal places in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        double pi = 3.14159265359;
        
        double rounded = Math.ceil(pi * 100) / 100;
        
        System.out.println(rounded);
    }
}




/*
run:
     
3.15

*/

 



answered Nov 24, 2023 by avibootz

Related questions

3 answers 194 views
1 answer 250 views
3 answers 285 views
1 answer 111 views
1 answer 131 views
3 answers 314 views
...