Add compute rate
This commit is contained in:
parent
ad27257db7
commit
cb28bc0d6a
@ -1,26 +1,23 @@
|
||||
package com.cubetiqs.libra.moneyutils
|
||||
|
||||
open class Money(
|
||||
private var value: Double,
|
||||
private var currency: String = "USD"
|
||||
var value: Double,
|
||||
var currency: String = "USD"
|
||||
) : StdMoney {
|
||||
override fun getValue(): Double {
|
||||
|
||||
//////////////////// - PROPERTIES - ////////////////////
|
||||
|
||||
override fun getMoneyValue(): Double {
|
||||
return this.value
|
||||
}
|
||||
|
||||
fun setValue(value: Double) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
override fun getCurrency(): String {
|
||||
override fun getMoneyCurrency(): String {
|
||||
return this.currency.toUpperCase()
|
||||
}
|
||||
|
||||
fun setCurrency(currency: String) {
|
||||
this.currency = currency
|
||||
}
|
||||
//////////////////// - GENERIC - ////////////////////
|
||||
|
||||
override fun toString(): String {
|
||||
return "Money(value=${getValue()}, currency='${getCurrency()}')"
|
||||
return "Money(value=${getMoneyValue()}, currency='${getMoneyCurrency()}')"
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.cubetiqs.libra.moneyutils
|
||||
|
||||
object MoneyExchangeUtils {
|
||||
fun computeRate(rateFrom: Double, rateTo: Double, baseRate: Double = 1.0, amountFrom: Double = 1.0): Double {
|
||||
return amountFrom * ((baseRate / rateFrom) / (baseRate / rateTo))
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.cubetiqs.libra.moneyutils
|
||||
|
||||
operator fun Money.unaryMinus() = (-value)
|
||||
operator fun Money.unaryPlus() = (+value)
|
||||
operator fun Money.unaryMinus() = (-getMoneyValue())
|
||||
operator fun Money.unaryPlus() = (+getMoneyValue())
|
||||
operator fun Money.inc() = Money(value++)
|
||||
operator fun Money.dec() = Money(value--)
|
||||
operator fun Money.plus(other: Money) = Money(value + other.value)
|
||||
|
@ -13,12 +13,12 @@ interface StdMoney {
|
||||
*
|
||||
* @return Double
|
||||
*/
|
||||
fun getValue(): Double
|
||||
fun getMoneyValue(): Double
|
||||
|
||||
/**
|
||||
* Get money's currency from current state.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
fun getCurrency(): String
|
||||
fun getMoneyCurrency(): String
|
||||
}
|
Loading…
Reference in New Issue
Block a user