1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Freezing couple of more string '0' & '.' and using the string appending to do the same string manipulation. This was we avoid the duplicate strings with freeze and append modifies existing string

This commit is contained in:
Ankit Gupta 2016-04-11 13:25:04 -07:00
parent 0db9c83a60
commit 9c30e1b167

View file

@ -29,9 +29,11 @@ module ActiveSupport
formatted_string = formatted_string =
if BigDecimal === rounded_number && rounded_number.finite? if BigDecimal === rounded_number && rounded_number.finite?
s = rounded_number.to_s('F') + '0'*precision s = rounded_number.to_s('F')
s << '0'.freeze * precision
a, b = s.split('.'.freeze, 2) a, b = s.split('.'.freeze, 2)
a + '.' + b[0, precision] a << '.'.freeze
a << b[0, precision]
else else
"%00.#{precision}f" % rounded_number "%00.#{precision}f" % rounded_number
end end