Class: Istox::FMath
- Inherits:
-
Object
- Object
- Istox::FMath
- Defined in:
- lib/istox/helpers/f_math.rb
Class Method Summary collapse
- .add(x, y) ⇒ Object
- .div(x, y) ⇒ Object
- .mul(x, y) ⇒ Object
- .round_down(x, digits) ⇒ Object
- .round_up(x, digits) ⇒ Object
- .sub(x, y) ⇒ Object
Class Method Details
.add(x, y) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/istox/helpers/f_math.rb', line 5 def add(x, y) BigDecimal.mode(BigDecimal::ROUND_MODE, :down) x = 0 if x.blank? y = 0 if y.blank? x = ::BigDecimal.new(x.to_s) y = ::BigDecimal.new(y.to_s) return x.add(y, 100).truncate(18).to_s end |
.div(x, y) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/istox/helpers/f_math.rb', line 41 def div(x, y) BigDecimal.mode(BigDecimal::ROUND_MODE, :down) x = 0 if x.blank? y = 0 if y.blank? x = ::BigDecimal.new(x.to_s) y = ::BigDecimal.new(y.to_s) return x.div(y, 100).truncate(18).to_s end |
.mul(x, y) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/istox/helpers/f_math.rb', line 29 def mul(x, y) BigDecimal.mode(BigDecimal::ROUND_MODE, :down) x = 0 if x.blank? y = 0 if y.blank? x = ::BigDecimal.new(x.to_s) y = ::BigDecimal.new(y.to_s) return x.mult(y, 100).truncate(18).to_s end |
.round_down(x, digits) ⇒ Object
59 60 61 62 63 |
# File 'lib/istox/helpers/f_math.rb', line 59 def round_down(x, digits) BigDecimal.mode(BigDecimal::ROUND_MODE, :down) x = 0 if x.blank? ::BigDecimal.new(x.to_s).round(digits).to_s end |
.round_up(x, digits) ⇒ Object
53 54 55 56 57 |
# File 'lib/istox/helpers/f_math.rb', line 53 def round_up(x, digits) BigDecimal.mode(BigDecimal::ROUND_MODE, :up) x = 0 if x.blank? ::BigDecimal.new(x.to_s).round(digits).to_s end |
.sub(x, y) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/istox/helpers/f_math.rb', line 17 def sub(x, y) BigDecimal.mode(BigDecimal::ROUND_MODE, :down) x = 0 if x.blank? y = 0 if y.blank? x = ::BigDecimal.new(x.to_s) y = ::BigDecimal.new(y.to_s) return x.sub(y, 100).truncate(18).to_s end |