Added parameter countDecimalPlaces to format() as is not generic on all platforms (e.g. doesn't work on iOS)
This commit is contained in:
parent
a101a37db2
commit
27dd8c98cc
|
@ -16,6 +16,6 @@ expect class BigDecimal {
|
||||||
constructor(double: Double)
|
constructor(double: Double)
|
||||||
|
|
||||||
|
|
||||||
fun format(pattern: String): String
|
fun format(countDecimalPlaces: Int): String
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,11 +23,11 @@ actual class BigDecimal(val decimal: NSDecimalNumber) { // it's almost impossibl
|
||||||
actual constructor(decimal: String) : this(decimal.toDouble())
|
actual constructor(decimal: String) : this(decimal.toDouble())
|
||||||
|
|
||||||
|
|
||||||
actual fun format(pattern: String): String {
|
actual fun format(countDecimalPlaces: Int): String {
|
||||||
val formatter = NSNumberFormatter()
|
val formatter = NSNumberFormatter()
|
||||||
|
|
||||||
formatter.positiveFormat = pattern
|
formatter.minimumFractionDigits = countDecimalPlaces.toULong()
|
||||||
formatter.negativeFormat = pattern
|
formatter.maximumFractionDigits = countDecimalPlaces.toULong()
|
||||||
|
|
||||||
return formatter.stringFromNumber(this.decimal) ?: ""
|
return formatter.stringFromNumber(this.decimal) ?: ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ actual class BigDecimal actual constructor(decimal: String) : java.math.BigDecim
|
||||||
actual constructor(double: Double) : this(java.math.BigDecimal.valueOf(double).toPlainString()) // for object deserializers
|
actual constructor(double: Double) : this(java.math.BigDecimal.valueOf(double).toPlainString()) // for object deserializers
|
||||||
|
|
||||||
|
|
||||||
actual fun format(pattern: String): String {
|
actual fun format(countDecimalPlaces: Int): String {
|
||||||
return String.format(pattern, this)
|
return String.format("%.0${countDecimalPlaces}f", this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ open class BankingPresenter(
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun formatAmount(amount: BigDecimal): String {
|
open fun formatAmount(amount: BigDecimal): String {
|
||||||
return amount.format("%.02f")
|
return amount.format(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue