Fixed Amount for wasmJs

This commit is contained in:
dankito 2024-09-12 03:56:34 +02:00
parent bf211e238f
commit 52af60077a
1 changed files with 10 additions and 8 deletions

View File

@ -3,7 +3,6 @@ package net.codinux.banking.client.model
import net.codinux.banking.client.model.config.NoArgConstructor import net.codinux.banking.client.model.config.NoArgConstructor
@JsModule("big.js") @JsModule("big.js")
@kotlin.js.JsNonModule
open external class Big(value: String) { open external class Big(value: String) {
fun plus(other: Big): Big fun plus(other: Big): Big
fun minus(other: Big): Big fun minus(other: Big): Big
@ -14,38 +13,41 @@ open external class Big(value: String) {
@NoArgConstructor @NoArgConstructor
actual class Amount actual constructor(amount: String): Big(amount) { actual class Amount actual constructor(amount: String) {
actual companion object { actual companion object {
actual val Zero = Amount("0.00") actual val Zero = Amount("0.00")
} }
internal val amount = Big(amount)
actual operator fun plus(other: Amount): Amount { actual operator fun plus(other: Amount): Amount {
return Amount(super.plus(other).toString()) return Amount(amount.plus(other.amount).toString())
} }
actual operator fun minus(other: Amount): Amount { actual operator fun minus(other: Amount): Amount {
return Amount(super.minus(other).toString()) return Amount(amount.minus(other.amount).toString())
} }
actual operator fun times(other: Amount): Amount { actual operator fun times(other: Amount): Amount {
return Amount(super.times(other).toString()) return Amount(amount.times(other.amount).toString())
} }
actual operator fun div(other: Amount): Amount { actual operator fun div(other: Amount): Amount {
return Amount(super.div(other).toString()) return Amount(amount.div(other.amount).toString())
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
return other is Amount && this.toString() == other.toString() return other is Amount && amount.toString() == other.amount.toString()
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return super.hashCode() return super.hashCode()
} }
actual override fun toString(): String = super.toString() actual override fun toString(): String = amount.toString()
} }