Last active
September 13, 2019 11:44
-
-
Save hkurokawa/a24e2f238f12fdb1a0c212baea4809c8 to your computer and use it in GitHub Desktop.
A function to round down to 2 decimal places which has a bug
This file contains hidden or 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
# This function rounds down the given value to 2 decimal places | |
# **Note!** This implementation looks correct but actually is wrong | |
def floor_2(value) | |
return (value.to_f * 100).floor.to_f / 100 | |
end | |
p floor_2(3.1415) # => 3.14 | |
p floor_2(2.71828) # => 2.71 | |
p floor_2(33.62) # => 33.61 !? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment