Add adavanced money formatter and decimal functions for money format and add function builder and money extension updated and add money view for money module

Add money formatter provider for general provider formatter
This commit is contained in:
2021-02-09 12:05:02 +07:00
parent 7497e11ee3
commit 003e1a59db
8 changed files with 293 additions and 20 deletions

View File

@@ -73,7 +73,7 @@ infix fun Number.withCurrency(currency: String): StdMoney = this withCurrency ob
// toString function for StdMoney interface
fun StdMoney.asString(): String = "StdMoney(value=${getValue()}, currency=${getCurrency().getCurrency()})"
fun StdMoney.asMoneyString(): String = "${getValue()}:${getCurrency().getCurrency()}"
fun StdMoney.asMoneyString(deli: Char? = ':'): String = "${getValue()}${deli ?: ':'}${getCurrency().getCurrency()}"
fun String?.fromStringToMoney(): StdMoney {
val values = this?.split(":")
if (values.isNullOrEmpty()) {
@@ -110,16 +110,20 @@ fun StdMoney.tryToCastToMixin(): MoneyMixin {
}
}
inline fun buildMoneyConfigProperties(
builderAction: MoneyConfig.MoneyConfigProperties.MoneyConfigPropertiesBuilder.() -> Unit
): MoneyConfig.MoneyConfigProperties {
return MoneyConfig
.builder().apply(builderAction)
.build()
// transfer std money to money view
fun StdMoney.asMoneyView(): MoneyView {
return MoneyView(this)
}
inline fun applyMoneyConfig(
builderAction: MoneyConfig.() -> Unit,
) {
MoneyConfig.apply(builderAction)
// transfer money view to std money
fun MoneyView.asStdMoney(): StdMoney {
return object : StdMoney {
override fun getCurrency(): StdMoney.Currency {
return StdMoney.initCurrency(this@asStdMoney.getCurrency())
}
override fun getValue(): Double {
return this@asStdMoney.getValue()
}
}
}