Skip to content

Instantly share code, notes, and snippets.

@jgarber
Forked from prathe/gist:1628799
Created October 4, 2012 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarber/3833029 to your computer and use it in GitHub Desktop.
Save jgarber/3833029 to your computer and use it in GitHub Desktop.
BigDecimal#to_s without trailing zero
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