aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/number_helper
Commit message (Collapse)AuthorAgeFilesLines
* Suppress `warning: BigDecimal.new is deprecated`Yasuo Honda2017-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | `BigDecimal.new` has been deprecated in BigDecimal 1.3.3 which will be a default for Ruby 2.5. Refer https://github.com/ruby/bigdecimal/commit/533737338db915b00dc7168c3602e4b462b23503 * This commit has been made as follows: ``` cd rails git grep -l BigDecimal.new | grep -v guides/source/5_0_release_notes.md | grep -v activesupport/test/xml_mini_test.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g" ``` - `activesupport/test/xml_mini_test.rb` Editmanually to remove `.new` and `::` - guides/source/5_0_release_notes.md This is a Rails 5.0 release notes.
* Remove unused `calculate_rounded_number` and `digit_count`yuuji.yaginuma2017-11-041-8/+0
| | | | These methods unused since 5533696.
* [Active Support] require_relative => requireAkira Matsuda2017-10-212-6/+6
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* Remove unused `NumberToRoundedConverter#digits_and_rounded_number`yuuji.yaginuma2017-09-191-12/+0
| | | | `digits_and_rounded_number` is unused since #26628
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-119-0/+9
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-099-0/+9
|
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-021-1/+1
|\
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-029-9/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-029-0/+9
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-019-0/+9
| | |
| * | Make ActiveSupport frozen string literal friendly.Pat Allan2017-06-201-1/+1
| |/ | | | | | | | | | | | | The ActiveSupport test suite only passes currently if it uses the latest unreleased commits for dalli, and a patch for Builder: https://github.com/tenderlove/builder/pull/6 Beyond that, all external dependencies (at least, to the extent they’re used by ActiveSupport) are happy, including Nokogiri as of 1.8.0.
* / [Active Support] require => require_relativeAkira Matsuda2017-07-012-6/+6
|/
* Don't create extra assignment, just returnVipul A M2017-06-041-3/+3
|
* number_to_human_converter: round before calculating exponentMichael Hoy2017-03-161-4/+2
| | | | fixes #25664
* number_to_rounded_converter: extract rounding logicMichael Hoy2017-03-162-26/+70
|
* No need to nodoc private methodsAkira Matsuda2016-12-241-5/+5
|
* Remove deprecated :prefix optionAndrew White2016-11-131-5/+1
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-294-4/+4
|
* applies remaining conventions across the projectXavier Noria2016-08-062-2/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-062-2/+0
|
* modernizes hash syntax in activesupportXavier Noria2016-08-062-4/+4
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-067-23/+23
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Freezing couple of more string '0' & '.' and using the string appending to ↵Ankit Gupta2016-04-111-2/+4
| | | | do the same string manipulation. This was we avoid the duplicate strings with freeze and append modifies existing string
* Freezing the dots as they are causing extra string initialization on every ↵Ankit Gupta2016-04-102-2/+2
| | | | iteration of calling the helper. Eases on some memory bloat
* `number_to_phone` formats number with regexpPan GaoYong2016-04-021-2/+11
| | | | | | | | | | | | 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.
* Fix broken number_to_currency testsPrathamesh Sonpatki2016-01-291-0/+2
|
* Change number_to_currency behavior for checking negativityPrathamesh Sonpatki2016-01-291-5/+1
| | | | | | | | | | | - 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/+1
|
* Merge pull request #20872 from maxjacobson/more-humane-roundingSean Griffin2015-10-201-2/+4
|\ | | | | | | Round some numbers more humanely
| * Round some numbers more humanelyMax Jacobson2015-07-261-2/+4
| | | | | | | | Fix #20869
* | - Extracted `DELIMITED_REGEX` to `delimited_regex` method and made use of ↵Vipul A M2015-08-281-2/+7
| | | | | | | | | | | | | | | | | | | | 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 the :prefix option of `number_to_human_size`Jean Boussier2015-08-101-0/+4
|/
* Give respond_to? a SymbolAkira Matsuda2015-05-201-1/+1
|
* Freeze static arguments for gsubbrainopia2015-04-024-4/+4
|
* Prefer string patterns for gsubbrainopia2015-04-024-4/+4
| | | | | | | | | | | | | | | | | https://github.com/ruby/ruby/pull/579 - there is a new optimization since ruby 2.2 Previously regexp patterns were faster (since a string was converted to regexp underneath anyway). But now string patterns are faster and better reflect the purpose. Benchmark.ips do |bm| bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') } bm.report('string') { 'this is ::a random string'.gsub('::', '/') } bm.compare! end # string: 753724.4 i/s # regexp: 501443.1 i/s - 1.50x slower
* `number_to_percentage` and `precision: 0` work with `NAN` and `INFINITY`.Yves Senn2015-03-061-1/+1
| | | | Closes #19227.
* Doc fix [ci skip]Sushruth Sivaramakrishnan2015-03-051-2/+2
|
* Merge pull request #12067 from jackxxu/keep_precisionRafael Mendonça França2015-02-061-25/+28
| | | | | | | | | 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
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Do gsub with a regexp instead of a stringPablo Herrero2014-10-292-2/+2
|
* Use zero-padding for number_to_rounded_converterZachary Scott2014-08-221-1/+1
|
* Fixes the digits counter of AS's NumberToRoundedConverterXavier Noria2014-08-201-1/+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-5/+1
| | | | | | | | | | :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"
* Use block parameter rather than `$1` during `gsub!` so ↵Mark J. Titorenko2014-05-121-1/+3
| | | | | | `ActiveSupport::SafeBuffer` values aren't mangled. Fixes #15064
* fix `number_to_percentage` with `Float::NAN`, `Float::INFINITY`.Yves Senn2014-03-171-2/+1
| | | | | | | 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-7/+37
| | | | | | | | | before: ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50 => "3.14158999999999988261834005243144929409027099609375" after: ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50 => "3.14159000000000000000000000000000000000000000000000"
* Nodoc missing number helper classes in AS [ci skip]Carlos Antonio da Silva2013-12-112-2/+2
| | | | These classes are not meant to be public.
* Remove earlier return in favor of conditionalCarlos Antonio da Silva2013-12-031-6/+9
|
* Change delimiter check order: first check if it is presentCarlos Antonio da Silva2013-12-031-3/+3
| | | | | | | This reads a lot better, and we won't need to try start_with? for blank delimiters. Also rename method name to read better.
* Make both conversion methods work similarlyCarlos Antonio da Silva2013-12-031-1/+2
| | | | | The conversion without area code already changed the passed number in place, so change the other method to do the same.