Add find currency from java built-in and fixed for money view
This commit is contained in:
parent
003e1a59db
commit
0676972a83
@ -1,5 +1,7 @@
|
|||||||
package com.cubetiqs.money
|
package com.cubetiqs.money
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
infix fun StdMoney.exchangeTo(currency: StdMoney.Currency): StdMoney {
|
infix fun StdMoney.exchangeTo(currency: StdMoney.Currency): StdMoney {
|
||||||
return MoneyExchangeUtils.exchange(this, currency)
|
return MoneyExchangeUtils.exchange(this, currency)
|
||||||
}
|
}
|
||||||
@ -126,4 +128,9 @@ fun MoneyView.asStdMoney(): StdMoney {
|
|||||||
return this@asStdMoney.getValue()
|
return this@asStdMoney.getValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// detect currency symbol, if needed
|
||||||
|
fun StdMoney.Currency.findCurrency(): Currency? {
|
||||||
|
return Currency.getInstance(this.getCurrency())
|
||||||
}
|
}
|
@ -4,9 +4,12 @@ open class MoneyView(
|
|||||||
private var value: Number? = null,
|
private var value: Number? = null,
|
||||||
private var currency: String? = null,
|
private var currency: String? = null,
|
||||||
) : MoneyMixin {
|
) : MoneyMixin {
|
||||||
|
private var _currency: StdMoney.Currency? = null
|
||||||
|
|
||||||
constructor(money: StdMoney) : this() {
|
constructor(money: StdMoney) : this() {
|
||||||
|
this._currency = money.getCurrency()
|
||||||
this.value = money.getValue()
|
this.value = money.getValue()
|
||||||
this.currency = money.getCurrency().getCurrency()
|
this.currency = this._currency?.getCurrency()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getValue(): Double {
|
fun getValue(): Double {
|
||||||
@ -17,6 +20,10 @@ open class MoneyView(
|
|||||||
return currency
|
return currency
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSymbol(): String? {
|
||||||
|
return this._currency?.findCurrency()?.symbol
|
||||||
|
}
|
||||||
|
|
||||||
fun getFormat(): String {
|
fun getFormat(): String {
|
||||||
return MoneyConfig
|
return MoneyConfig
|
||||||
.getFormatter(getCurrency())
|
.getFormatter(getCurrency())
|
||||||
|
Loading…
Reference in New Issue
Block a user