Add money extension and operator

This commit is contained in:
Sambo Chea 2020-08-27 10:48:31 +07:00
parent 377809383d
commit 4dc6ae521c
2 changed files with 11 additions and 9 deletions

View File

@ -0,0 +1,3 @@
package com.cubetiqs.libra.moneyutils
fun StdMoney

View File

@ -1,13 +1,12 @@
package com.cubetiqs.libra.moneyutils
operator fun Money.unaryMinus() = (-getMoneyValue())
operator fun Money.unaryPlus() = (+getMoneyValue())
operator fun StdMoney.unaryMinus() = (-getMoneyValue())
operator fun StdMoney.unaryPlus() = (+getMoneyValue())
operator fun Money.inc() = Money(value++)
operator fun Money.dec() = Money(value--)
operator fun Money.plus(other: Money) = Money(value + other.value)
operator fun Money.times(other: Money) = Money(value * other.value)
operator fun Money.div(other: Money) = Money(value / other.value)
operator fun Money.timesAssign(other: Money) {
this.value = this.value * other.value
}
operator fun Money.not() = this.value != this.value
operator fun StdMoney.plus(other: StdMoney) = Money(getMoneyValue() + other.getMoneyValue())
operator fun StdMoney.times(other: StdMoney) = Money(getMoneyValue() * other.getMoneyValue())
operator fun StdMoney.div(other: StdMoney) = Money(getMoneyValue() / other.getMoneyValue())
operator fun Money.timesAssign(other: StdMoney) {
this.value = this.getMoneyValue() * other.getMoneyValue()
}