foodsoft/config/initializers/number_display.rb

23 lines
448 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
2014-11-21 14:37:56 +01:00
# allow +to_s+ on bigdecimal without argument too
2013-12-14 00:19:18 +01:00
if defined? BigDecimal
class BigDecimal
alias :foodsoft_to_s :to_s
2014-11-21 14:37:56 +01:00
def to_s(*args)
if args.present?
foodsoft_to_s(*args)
else
foodsoft_to_s(*args).gsub /(\.0*|(\.[0-9]+?)0+)$/, '\2'
end
2013-12-14 00:19:18 +01:00
end
end
end