Class: ActiveSupport::NumberHelper::RoundingHelper

Inherits:
Object
  • Object
show all
Defined in:
activesupport/lib/active_support/number_helper/rounding_helper.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RoundingHelper

Returns a new instance of RoundingHelper.



8
9
10
# File 'activesupport/lib/active_support/number_helper/rounding_helper.rb', line 8

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options



6
7
8
# File 'activesupport/lib/active_support/number_helper/rounding_helper.rb', line 6

def options
  @options
end

Instance Method Details

#digit_count(number) ⇒ Object



22
23
24
25
# File 'activesupport/lib/active_support/number_helper/rounding_helper.rb', line 22

def digit_count(number)
  return 1 if number.zero?
  (Math.log10(absolute_number(number)) + 1).floor
end

#round(number) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'activesupport/lib/active_support/number_helper/rounding_helper.rb', line 12

def round(number)
  return number unless precision
  number = convert_to_decimal(number)
  if significant && precision > 0
    round_significant(number)
  else
    round_without_significant(number)
  end
end