I'm seeing differences between the built in round()
function in Python and Java's java.lang.Math.round()
function.
In Python we see..
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> round(0.0)
0.0
>>> round(0.5)
1.0
>>> round(-0.5)
-1.0
And in Java..
System.out.println("a: " + Math.round(0.0));
System.out.println("b: " + Math.round(0.5));
System.out.println("c: " + Math.round(-0.5));
a: 0
b: 1
c: 0
Looks like Java is always rounding up while Python rounds down for negative numbers.
What's the best way to get Python style rounding behavior in Java?