From bf211e238f5c6236bf169339eb6873e9dc2c15ca Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 12 Sep 2024 03:47:05 +0200 Subject: [PATCH] Fixed Amount for Apple platforms --- .../banking/client/model/Amount.apple.kt | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/BankingClientModel/src/appleMain/kotlin/net/codinux/banking/client/model/Amount.apple.kt b/BankingClientModel/src/appleMain/kotlin/net/codinux/banking/client/model/Amount.apple.kt index 28010e65..0017c791 100644 --- a/BankingClientModel/src/appleMain/kotlin/net/codinux/banking/client/model/Amount.apple.kt +++ b/BankingClientModel/src/appleMain/kotlin/net/codinux/banking/client/model/Amount.apple.kt @@ -2,28 +2,42 @@ package net.codinux.banking.client.model import platform.Foundation.NSDecimalNumber import net.codinux.banking.client.model.config.NoArgConstructor +import platform.Foundation.NSDecimalNumberHandler +import platform.Foundation.NSRoundingMode @NoArgConstructor -actual class Amount actual constructor(amount: String) : NSDecimalNumber(string = amount) { +actual class Amount actual constructor(amount: String) { actual companion object { actual val Zero = Amount("0.00") + + private val handler = NSDecimalNumberHandler.decimalNumberHandlerWithRoundingMode(roundingMode = NSRoundingMode.NSRoundBankers, scale = DecimalPrecision.toShort(), false, false, false, false) } + internal val amount = NSDecimalNumber(string = amount) + + actual operator fun plus(other: Amount): Amount = - Amount(this.decimalNumberByAdding(other).stringValue) + Amount(amount.decimalNumberByAdding(other.amount).stringValue) actual operator fun minus(other: Amount): Amount = - Amount(this.decimalNumberBySubtracting(other).stringValue) + Amount(amount.decimalNumberBySubtracting(other.amount).stringValue) actual operator fun times(other: Amount): Amount = - Amount(this.decimalNumberByMultiplyingBy(other).stringValue) + Amount(amount.decimalNumberByMultiplyingBy(other.amount).stringValue) actual operator fun div(other: Amount): Amount = - Amount(this.decimalNumberByDividingBy(other).stringValue) + Amount(amount.decimalNumberByDividingBy(other.amount, handler).stringValue) - actual override fun toString(): String = this.stringValue + override fun equals(other: Any?): Boolean { + return other is Amount && this.amount == other.amount + } + + override fun hashCode() = + amount.hashCode() + + actual override fun toString(): String = amount.stringValue } \ No newline at end of file