Created
April 19, 2011 14:04
-
-
Save semmons99/927927 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
def bankers_round(amount) | |
scaled_amt = amount * BigDecimal("100") | |
if scaled_amt.frac > BigDecimal("0.5") | |
return scaled_amt.ceil / BigDecimal("100") | |
elsif scaled_amt.frac < BigDecimal("0.5") | |
return scaled_amt.floor / BigDecimal("100") | |
end | |
return scaled_amt.floor / BigDecimal("100") if scaled_amt.to_i.even? | |
scaled_amt.ceil / BigDecimal("100") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment