Class: ActiveSupport::NumberHelper::RoundingHelper
- Defined in:
- lib/active_support/number_helper/rounding_helper.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #digit_count(number) ⇒ Object
-
#initialize(options) ⇒ RoundingHelper
constructor
A new instance of RoundingHelper.
- #round(number) ⇒ Object
Constructor Details
#initialize(options) ⇒ RoundingHelper
Returns a new instance of RoundingHelper.
8 9 10 |
# File 'lib/active_support/number_helper/rounding_helper.rb', line 8 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/active_support/number_helper/rounding_helper.rb', line 6 def @options end |
Instance Method Details
#digit_count(number) ⇒ Object
20 21 22 23 |
# File 'lib/active_support/number_helper/rounding_helper.rb', line 20 def digit_count(number) return 1 if number.zero? (Math.log10(number.abs) + 1).floor end |
#round(number) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/active_support/number_helper/rounding_helper.rb', line 12 def round(number) precision = absolute_precision(number) return number unless precision rounded_number = convert_to_decimal(number).round(precision, .fetch(:round_mode, :default)) rounded_number.zero? ? rounded_number.abs : rounded_number # prevent showing negative zeros end |