aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/number_helper_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* `number_to_phone` formats number with regexpPan GaoYong2016-04-021-0/+2
| | | | | | | | | | | | By default, this method formats US number. This commit extends its functionality to format number for other countries with a custom regular expression. number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/) # => 188-1234-5678 The output phone number is divided into three groups, so the regexp should also match three groups of numbers.
* Change number_to_currency behavior for checking negativityPrathamesh Sonpatki2016-01-291-1/+0
| | | | | | | | | | | - Instead of using `to_f.phase`, just use `to_f.negative`?. - This change works same for all cases except when number is "-0.0". -0.0.to_f.negative? => false -0.0.to_f.phase? => pi - So -0.0 will be treated as positive from now onwards. - So this change reverts changes from https://github.com/rails/rails/pull/6512. - But it should be acceptable as we could not find any currency which supports negative zeros.
* Add support for Petabyte and Exabyte in number to human sizeAkshay Vishnoi2015-12-221-1/+13
|
* Merge pull request #20872 from maxjacobson/more-humane-roundingSean Griffin2015-10-201-0/+2
|\ | | | | | | Round some numbers more humanely
| * Round some numbers more humanelyMax Jacobson2015-07-261-0/+2
| | | | | | | | Fix #20869
* | - Extracted `DELIMITED_REGEX` to `delimited_regex` method and made use of ↵Vipul A M2015-08-281-0/+1
| | | | | | | | | | | | | | | | | | | | 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
* | Deprecate :si prefix in number_to_human_size without replacementJean Boussier2015-08-101-9/+11
|/
* `number_to_percentage` and `precision: 0` work with `NAN` and `INFINITY`.Yves Senn2015-03-061-0/+4
| | | | Closes #19227.
* Merge pull request #12067 from jackxxu/keep_precisionRafael Mendonça França2015-02-061-0/+4
|\ | | | | | | | | | | | | | | | | Enable number_to_percentage to keep the number's precision by allowing :precision option value to be nil Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/number_helper.rb activesupport/test/number_helper_test.rb
| * Enable number_to_percentage to keep the number's precision by allowing ↵Jack Xu2013-08-281-0/+4
| | | | | | | | | | | | :precision to be nil number_helper.number_to_percentage(1000, precision: nil) # => "1000%"
* | Fixes the digits counter of AS's NumberToRoundedConverterXavier Noria2014-08-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | Zero has one digit, but Math.log10(0) returns -Infinity. The method needs to special-case zero. The patch adds a regression test that is not clearly related to the underlying issue because digit_count is private and has no coverage. Gray area. This bug was uncovered by 60062cf.
* | Fix AS::NumberHelper results with rationalsJuanjo Bazán2014-05-311-0/+2
| | | | | | | | | | | | | | | | | | | | :precision was incorrectly being applied to Rationals before: ActiveSupport::NumberHelper.number_to_rounded Rational(10, 3), precision: 2 => "3.3" after: ActiveSupport::NumberHelper.number_to_rounded Rational(10, 3), precision: 2 => "3.33"
* | Require active_support/core_ext/string/output_safety and use html_safe ↵Mark J. Titorenko2014-05-121-1/+2
| | | | | | | | rather than use non-public SafeBuffer API.
* | Use block parameter rather than `$1` during `gsub!` so ↵Mark J. Titorenko2014-05-121-0/+1
| | | | | | | | | | | | `ActiveSupport::SafeBuffer` values aren't mangled. Fixes #15064
* | fix `number_to_percentage` with `Float::NAN`, `Float::INFINITY`.Yves Senn2014-03-171-0/+3
| | | | | | | | | | | | | | Closes #14405. This is a follow-up to 9e997e9039435617b6a844158f5437e97f6bc107 to restore the documented behavior.
* | Fix AS::NumberHelper results with large precisionsKenta Murata & Akira Matsuda2013-12-201-0/+14
| | | | | | | | | | | | | | | | | | before: ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50 => "3.14158999999999988261834005243144929409027099609375" after: ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50 => "3.14159000000000000000000000000000000000000000000000"
* | removed duplicate test caseKuldeep Aggarwal2013-12-041-1/+0
| |
* | Extract ActiveSupport::NumberHelper methods to classesMatt Bridges2013-07-011-6/+0
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to the overall complexity of each method individually as well as the global shared private module methods, this pulls each helper into it's own converter class inheriting from a generic `NumberBuilder` class. * The `NumberBuilder` class contains the private methods needed for each helper method an eliminates the need for special definition of specialized private module methods. * The `ActiveSupport::NumberHelper::DEFAULTS` constant has been moved into the `NumberBuilder` class because the `NumberBuilder` is the only class which needs access to it. * For each of the builders, the `#convert` method is broken down to smaller parts and extracted into private methods for clarity of purpose. * Most of the mutation that once was necessary has now been eliminated. * Several of the mathematical operations for percentage, delimited, and rounded have been moved into private methods to ease readability and clarity. * Internationalization is still a bit crufty, and definitely could be improved, but it is functional and a bit easier to follow. The following helpers were extracted into their respective classes. * `#number_to_percentage` -> `NumberToPercentageConverter` * `#number_to_delimited` -> `NumberToDelimitedConverter` * `#number_to_phone` -> `NumberToPhoneConverter` * `#number_to_currency` -> `NumberToCurrencyConverter` * `#number_to_rounded` -> `NumberToRoundedConverter` * `#number_to_human_size` -> `NumberToHumanSizeConverter` * `#number_to_human` -> `NumberToHumanConverter`
* Move number_to_human test from AP to ASCarlos Antonio da Silva2013-02-221-0/+7
| | | | | Since all changes from #9347 are related to AS, it seems proper that the test is placed there as well.
* Ensure I18n format values always have precedence over defaultsCarlos Antonio da Silva2012-08-111-1/+0
| | | | | | | | | | | | | | | | | | | Always merge I18n format values, namespaced or not, over the default ones, to ensure I18n format defaults will have precedence over our namespaced values. Precedence should happen like this: default :format default :namespace :format i18n :format i18n :namespace :format Because we cannot allow our namespaced default to override a I18n :format config - ie precision in I18n :format should always have higher precedence than our default precision for a particular :namespace. Also simplify default format options logic.
* Fallback to :en locale instead of handling a constant with defaultsCarlos Antonio da Silva2012-08-111-3/+3
| | | | | | | | Action Pack already comes with a default locale fine for :en, that is always loaded. We can just fallback to this locale for defaults, if values for the current locale cannot be found. Closes #4420, #2802, #2890.
* Fix handling of negative zero in number_to_currencyJared Beck2012-05-281-0/+2
|
* Moving NumberHelpers from ActionView to ActiveSupportAndrew Mutz2012-05-271-0/+373