-
-
Save jgarber/3833029 to your computer and use it in GitHub Desktop.
BigDecimal#to_s without trailing zero
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
class BigDecimalWithoutTrailingZeroes < BigDecimal | |
def to_digits | |
_, significant_digits, _, exponent = split | |
if zero? | |
'0' | |
elsif exponent >= significant_digits.size | |
to_i.to_s | |
else | |
to_s('F') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment