diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt index b6574f5..28d5e21 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt @@ -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) {