Added thousands separator
This commit is contained in:
parent
0696af3956
commit
fff86145b2
|
@ -32,10 +32,21 @@ class FormatUtil {
|
|||
|
||||
fun formatAmount(amount: Amount, currency: String): String { // TODO: find a better way
|
||||
val parts = amount.amount.split('.')
|
||||
|
||||
var integerPart = parts[0]
|
||||
val isNegative = integerPart.startsWith("-")
|
||||
|
||||
if ((isNegative && integerPart.length > 7) || (isNegative == false && integerPart.length > 6)) {
|
||||
integerPart = (integerPart.substring(0, integerPart.length - 6) + "." + integerPart.substring(integerPart.length - 6))
|
||||
}
|
||||
if ((isNegative && integerPart.length > 4) || (isNegative == false && integerPart.length > 3)) {
|
||||
integerPart = (integerPart.substring(0, integerPart.length - 3) + "." + integerPart.substring(integerPart.length - 3))
|
||||
}
|
||||
|
||||
val decimalPart = if (parts.size == 2) parts[1] else "00"
|
||||
|
||||
// TODO: add thousands separator
|
||||
return "${parts[0]},${decimalPart.padEnd(2, '0').substring(0, 2)} ${formatCurrency(currency)}"
|
||||
return "$integerPart,${decimalPart.padEnd(2, '0').substring(0, 2)} ${formatCurrency(currency)}"
|
||||
}
|
||||
|
||||
fun formatCurrency(currency: String): String = when (currency) {
|
||||
|
|
Loading…
Reference in New Issue