module
Money::Arithmetic
Direct including types
Defined in:
money/money/arithmetic.crInstance Method Summary
-
#%(other : Number | Money) : Money
Alias of
#modulo. - #*(other : Number) : Money
-
#+(other : Money) : Money
Returns a new
Moneyobject containing the sum of the two operands' monetary values. -
#+ : Money
Alias of
#abs. -
#-(other : Money) : Money
Returns a new
Moneyobject containing the difference between the two operands' monetary values. -
#- : Money
Returns a new
Moneyobject with changed polarity. - #/(other : Number) : Money
-
#/(other : Money) : BigDecimal
Divides the monetary value with the given other
Moneyobject and returns a ratio. -
#abs : Money
Returns absolute value of
selfas a newMoneyobject. - #divmod(other : Money) : Tuple(BigDecimal, Money)
- #divmod(other : Number) : Tuple(Money, Money)
-
#modulo(other : Number | Money) : Money
Equivalent to
#divmod(other)[1]. -
#negative?
Returns
trueif the money amount is less than 0,falseotherwise. -
#percentage(value : Number) : Money
Returns a new
Moneyobject containing the percentage of the monetary value. -
#positive?
Returns
trueif the money amount is greater than 0,falseotherwise. -
#remainder(other : Number) : Money
If different signs
#modulo(other) - other, otherwise#modulo(other). -
#sign : Int32
Returns the sign of the money amount.
-
#zero?
Returns
trueif the money amount is zero.
Instance Method Detail
Multiplies the monetary value with the given other Number and returns
a new Money object with this monetary value and the same #currency.
Money.new(1_00) * 2 # => Money(@amount=2.0)
Returns a new Money object containing the sum of the two
operands' monetary values.
Money.new(1_00) + Money.new(1_00) # => Money(@amount=2.0)
Returns a new Money object containing the difference between the two
operands' monetary values.
Money.new(1_00) - Money.new(99) # => Money(@amount=0.01)
Returns a new Money object with changed polarity.
-Money.new(1_00) # => Money(@amount=-1.0)
Divides the monetary value with the given other Number and returns
a new Money object with this monetary value and the same #currency.
Money.new(1_00) / 10 # => Money(@amount=0.1)
Divides the monetary value with the given other Money object and
returns a ratio.
Money.new(1_00) / Money.new(10) # => 10.0
Returns absolute value of self as a new Money object.
Money.new(-1_00).abs # => Money(@amount=1.0)
Divide by Money or Number and return Tuple containing
quotient and modulus.
Money.new(1_00).divmod(9) # => {Money(@amount=0.11), Money(@amount=0.01)}
Money.new(1_00).divmod(Money.new(9)) # => {11.0, Money(@amount=0.01)}
Divide by Money or Number and return Tuple containing
quotient and modulus.
Money.new(1_00).divmod(9) # => {Money(@amount=0.11), Money(@amount=0.01)}
Money.new(1_00).divmod(Money.new(9)) # => {11.0, Money(@amount=0.01)}
Equivalent to #divmod(other)[1].
Money.new(1_00).modulo(9) # => Money(@amount=0.01)
Money.new(1_00).modulo(Money.new(9)) # => Money(@amount=0.01)
Returns true if the money amount is less than 0, false otherwise.
Money.new(-100).negative? # => true
Money.new(0).negative? # => false
Money.new(100).negative? # => false
Returns a new Money object containing the percentage of the
monetary value.
Money.new(1_00).percentage(10) # => Money(@amount=0.1)
Returns true if the money amount is greater than 0, false otherwise.
Money.new(-100).positive? # => false
Money.new(0).positive? # => false
Money.new(100).positive? # => true
If different signs #modulo(other) - other, otherwise #modulo(other).
Money.new(1_00).remainder(9) # => Money(@amount=0.01)
Returns the sign of the money amount.
-1if the money amount is negative0if the money amount is zero1if the money amount is positive
Money.new(-100).sign # => -1
Money.new(0).sign # => 0
Money.new(100).sign # => 1
Returns true if the money amount is zero.
Money.new(-100).zero? # => false
Money.new(0).zero? # => true
Money.new(100).zero? # => false