Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Last active September 13, 2019 11:44
Show Gist options
  • Save hkurokawa/a24e2f238f12fdb1a0c212baea4809c8 to your computer and use it in GitHub Desktop.
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 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