Rounding up in java?

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
Is there a better way to round up numbers eg square roots than doing this? I can't find a method for rounding up in the Math class.

Code:
if (Math.sqrt(iterations) % 1 != 0) {
    System.out.println(Math.round(Math.sqrt(iterations) + 0.5));
} else {
    System.out.println(Math.round(Math.sqrt(iterations)));
}
 
Back
Top Bottom