| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
| |
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
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
| |
: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"
|
|
|
|
|
|
| |
`ActiveSupport::SafeBuffer` values aren't mangled.
Fixes #15064
|
|
|
|
|
|
|
| |
Closes #14405.
This is a follow-up to 9e997e9039435617b6a844158f5437e97f6bc107 to restore
the documented behavior.
|
|
|
|
|
|
|
|
|
| |
before:
ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50
=> "3.14158999999999988261834005243144929409027099609375"
after:
ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50
=> "3.14159000000000000000000000000000000000000000000000"
|
|
|
|
| |
These classes are not meant to be public.
|
| |
|
|
|
|
|
|
|
| |
This reads a lot better, and we won't need to try start_with? for blank
delimiters.
Also rename method name to read better.
|
|
|
|
|
| |
The conversion without area code already changed the passed number in
place, so change the other method to do the same.
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
number
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
| |
Refactor and clean up number helpers
Conflicts:
activesupport/lib/active_support/number_helper.rb
|
|
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`
|