Class: Maths::Formatter
- Inherits:
-
Object
- Object
- Maths::Formatter
- Defined in:
- lib/maths/formatter.rb
Class Method Summary collapse
-
.big_d_to_rational(val) ⇒ Object
Public: Converts a BigDecimal to either a float or an int, depending on its precision.
-
.format(val) ⇒ Object
Public: Formats values for us to output.
Class Method Details
.big_d_to_rational(val) ⇒ Object
Public: Converts a BigDecimal to either a float or an int, depending on its precision
24 25 26 27 28 29 30 |
# File 'lib/maths/formatter.rb', line 24 def self.big_d_to_rational(val) if val.frac == 0 val.to_i else val.to_f end end |
.format(val) ⇒ Object
Public: Formats values for us to output.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/maths/formatter.rb', line 4 def self.format(val) if val.nil? output = "Undefined" elsif !val.is_a?(Numeric) output = val.to_s elsif val.frac == 0 output = val.to_i.to_s else output = val.to_s("F") end if val.is_a?(Percentage) output += "%" end output end |