Permalink
Browse files

Fix format output with thousands separator

  • Loading branch information...
1 parent a9efafb commit ad022dd011eeff86006d8399286c1abff7eaf4e1 @alup alup committed with Mar 15, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/money/money/formatting.rb
@@ -204,7 +204,13 @@ def format(*rules)
end
# Apply thousands_separator
- formatted.gsub!(/(\d)(?=(?:\d{3})+(?:[^\d]|$))/, "\\1#{thousands_separator_value}")
+ regexp_decimal = Regexp.escape(decimal_mark)
+ regexp_format = if formatted =~ /#{regexp_decimal}/
+ /(\d)(?=(?:\d{3})+(?:#{regexp_decimal}))/
+ else
+ /(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))/
+ end
+ formatted.gsub!(regexp_format, "\\1#{thousands_separator_value}")
if rules[:with_currency]
formatted << " "

0 comments on commit ad022dd

Please sign in to comment.