mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #24502 from ankit8898/freezing-dot-in-delimiter-helper
Lesser '.' objects for number helpers
This commit is contained in:
commit
ecd53667fa
2 changed files with 6 additions and 4 deletions
|
@ -12,7 +12,7 @@ module ActiveSupport
|
|||
private
|
||||
|
||||
def parts
|
||||
left, right = number.to_s.split('.')
|
||||
left, right = number.to_s.split('.'.freeze)
|
||||
left.gsub!(delimiter_pattern) do |digit_to_delimit|
|
||||
"#{digit_to_delimit}#{options[:delimiter]}"
|
||||
end
|
||||
|
|
|
@ -29,9 +29,11 @@ module ActiveSupport
|
|||
|
||||
formatted_string =
|
||||
if BigDecimal === rounded_number && rounded_number.finite?
|
||||
s = rounded_number.to_s('F') + '0'*precision
|
||||
a, b = s.split('.', 2)
|
||||
a + '.' + b[0, precision]
|
||||
s = rounded_number.to_s('F')
|
||||
s << '0'.freeze * precision
|
||||
a, b = s.split('.'.freeze, 2)
|
||||
a << '.'.freeze
|
||||
a << b[0, precision]
|
||||
else
|
||||
"%00.#{precision}f" % rounded_number
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue