mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed NumberHelper#number_with_delimiter to use "." always for splitting the original number, not the delimiter parameter (closes #7389) [ceefour]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6045 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
0aa0c84c17
commit
28e77c9216
2 changed files with 7 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Fixed NumberHelper#number_with_delimiter to use "." always for splitting the original number, not the delimiter parameter #7389 [ceefour]
|
||||||
|
|
||||||
* Autolinking recognizes trailing and embedded . , : ; #7354 [Jarkko Laine]
|
* Autolinking recognizes trailing and embedded . , : ; #7354 [Jarkko Laine]
|
||||||
|
|
||||||
* Make TextHelper::auto_link recognize URLs with colons in path correctly, fixes #7268. [imajes]
|
* Make TextHelper::auto_link recognize URLs with colons in path correctly, fixes #7268. [imajes]
|
||||||
|
|
|
@ -94,16 +94,16 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
# Formats a +number+ with grouped thousands using +delimiter+. You
|
# Formats a +number+ with grouped thousands using +delimiter+. You
|
||||||
# can customize the format in the +options+ hash.
|
# can customize the format using optional <em>delimiter</em> and <em>separator</em> parameters.
|
||||||
# * <tt>:delimiter</tt> - Sets the thousands delimiter, defaults to ","
|
# * <tt>delimiter</tt> - Sets the thousands delimiter, defaults to ","
|
||||||
# * <tt>:separator</tt> - Sets the separator between the units, defaults to "."
|
# * <tt>separator</tt> - Sets the separator between the units, defaults to "."
|
||||||
#
|
#
|
||||||
# number_with_delimiter(12345678) => 12,345,678
|
# number_with_delimiter(12345678) => 12,345,678
|
||||||
# number_with_delimiter(12345678.05) => 12,345,678.05
|
# number_with_delimiter(12345678.05) => 12,345,678.05
|
||||||
# number_with_delimiter(12345678, :delimiter => ".") => 12.345.678
|
# number_with_delimiter(12345678, ".") => 12.345.678
|
||||||
def number_with_delimiter(number, delimiter=",", separator=".")
|
def number_with_delimiter(number, delimiter=",", separator=".")
|
||||||
begin
|
begin
|
||||||
parts = number.to_s.split(separator)
|
parts = number.to_s.split('.')
|
||||||
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
|
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
|
||||||
parts.join separator
|
parts.join separator
|
||||||
rescue
|
rescue
|
||||||
|
|
Loading…
Reference in a new issue