diff options
author | Vipul A M <vipulnsward@gmail.com> | 2014-11-04 12:52:41 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2015-08-28 11:34:17 +0530 |
commit | 7f23c5d52438f12d7af167a399a77025b1d58a9c (patch) | |
tree | e02e8752146e89548cf31cede51fa5eb474655c2 /activesupport/lib/active_support/number_helper.rb | |
parent | 2a6071a5e81cbc3b83625f5e6d5aff61c69f1720 (diff) | |
download | rails-7f23c5d52438f12d7af167a399a77025b1d58a9c.tar.gz rails-7f23c5d52438f12d7af167a399a77025b1d58a9c.tar.bz2 rails-7f23c5d52438f12d7af167a399a77025b1d58a9c.zip |
- Extracted `DELIMITED_REGEX` to `delimited_regex` method and made use of user passed `options[:delimited_regex]` if available. Changed `DELIMITED_REGEX` to `DEFAULT)DELIMITED_REGEX` to signify what it means.
- Added tests for number to delimited and number to currency in both actionview and activesupport.
Changes
Changes
Diffstat (limited to 'activesupport/lib/active_support/number_helper.rb')
-rw-r--r-- | activesupport/lib/active_support/number_helper.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 38a9ce361d..5ab0f0a7ea 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -135,6 +135,9 @@ module ActiveSupport # to ","). # * <tt>:separator</tt> - Sets the separator between the # fractional and integer digits (defaults to "."). + # * <tt>:delimiter_pattern</tt> - Sets a custom regular expression used for + # for deriving, the placement of delimiter. Helpful when using currency + # formats like INR. # # ==== Examples # @@ -147,6 +150,8 @@ module ActiveSupport # number_to_delimited(12345678.05, locale: :fr) # => 12 345 678,05 # number_to_delimited('112a') # => 112a # number_to_delimited(98765432.98, delimiter: ' ', separator: ',') + # number_helper.number_to_delimited("123456.78", + # delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/) # => 1,23,456.78 # # => 98 765 432,98 def number_to_delimited(number, options = {}) NumberToDelimitedConverter.convert(number, options) |