Created
January 17, 2012 20:51
-
-
Save prathe/1628799 to your computer and use it in GitHub Desktop.
BigDecimal#to_s without trailing zero
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
class BigDecimal | |
def to_s(s = 'F') | |
sign, significant_digits, base, exponent = self.split | |
if self.zero? | |
'0' | |
elsif significant_digits.size <= exponent | |
self.to_i.to_s | |
else | |
self.to_f.to_s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably not what you wanted...
Also probably shouldn't duck punch to_s. See my fork.