OnJava8-Examples/operators/RoundingNumbers.java
2015-09-07 11:44:36 -06:00

22 lines
629 B
Java

// operators/RoundingNumbers.java
// ©2015 MindView LLC: see Copyright.txt
// Rounding floats and doubles.
import static com.mindviewinc.util.Print.*;
public class RoundingNumbers {
public static void main(String[] args) {
double above = 0.7, below = 0.4;
float fabove = 0.7f, fbelow = 0.4f;
print("Math.round(above): " + Math.round(above));
print("Math.round(below): " + Math.round(below));
print("Math.round(fabove): " + Math.round(fabove));
print("Math.round(fbelow): " + Math.round(fbelow));
}
}
/* Output:
Math.round(above): 1
Math.round(below): 0
Math.round(fabove): 1
Math.round(fbelow): 0
*/