Fixed Amount for Apple platforms
This commit is contained in:
parent
fd7a3bc747
commit
bf211e238f
|
@ -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
|
||||
|
||||
}
|
Loading…
Reference in New Issue