Added Amount.isNegative and Collection<Amount>.sum() extension methods

This commit is contained in:
dankito 2024-09-12 03:58:22 +02:00
parent 52af60077a
commit 83dfd41784
1 changed files with 13 additions and 0 deletions

View File

@ -12,6 +12,19 @@ fun Amount.toFloat() =
fun Amount.toDouble() =
this.toString().toDouble()
val Amount.isNegative: Boolean
get() = this.toString().startsWith("-")
fun Collection<Amount>.sum(): Amount {
var sum: Amount = Amount.Zero
for (element in this) {
sum += element
}
return sum
}
@NoArgConstructor
expect class Amount(amount: String = "0") {