foodsoft/config/initializers/number_display.rb

18 lines
349 B
Ruby
Raw Normal View History

2013-12-14 00:19:18 +01:00
# we'd like to show "0.0" as "0"
class Float
alias :foodsoft_to_s :to_s
def to_s
2014-06-21 11:25:58 +02:00
foodsoft_to_s.gsub /(\.0*|(\.[0-9]+?)0+)$/, '\2'
2013-12-14 00:19:18 +01:00
end
end
if defined? BigDecimal
class BigDecimal
alias :foodsoft_to_s :to_s
def to_s(format = DEFAULT_STRING_FORMAT)
2014-06-21 11:25:58 +02:00
foodsoft_to_s(format).gsub /(\.0*|(\.[0-9]+?)0+)$/, '\2'
2013-12-14 00:19:18 +01:00
end
end
end