Added Amount.isNegative and Collection<Amount>.sum() extension methods
This commit is contained in:
parent
52af60077a
commit
83dfd41784
|
@ -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") {
|
||||
|
|
Loading…
Reference in New Issue