Created
October 18, 2010 09:46
-
-
Save gorenje/631981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Something that happened to me the other day -- rounding on the 5th value after the decimal point. | |
Ruby code that was tested: | |
puts "%.2f" % 1.234 | |
puts "%.2f" % 1.235 | |
puts "%.4f" % 1.23523 | |
puts "%.4f" % 1.23525 | |
The last value should be 1.2353 (at least that is what i learnt in my maths classes) | |
info: Using ruby 1.9.2 p0 | |
1.23 | |
1.24 | |
1.2352 | |
1.2352 ## Wrong | |
info: Using ree 1.8.7 2010.02 | |
1.23 | |
1.24 | |
1.2352 | |
1.2352 ## Wrong | |
info: Using ruby 1.9.2 preview3 | |
1.23 | |
1.24 | |
1.2352 | |
1.2352 ## Wrong | |
info: Using ruby 1.8.7 p174 | |
1.23 | |
1.24 | |
1.2352 | |
1.2352 ## Wrong | |
info: Using jruby head | |
1.23 | |
1.24 | |
1.2352 | |
1.2353 ## Correct! | |
So it seems that Java is simply the language to be using ;) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment