2015-04-20 15:36:01 -07:00
|
|
|
|
//: operators/RoundingNumbers.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// Rounding floats and doubles.
|
|
|
|
|
import static net.mindview.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
|
|
|
|
|
*///:~
|