fixed 0.00 places for amounts

This commit is contained in:
moon 2026-07-14 11:41:11 +06:30
parent c3faee2eb0
commit e0baafb84d
2 changed files with 14 additions and 18 deletions

View File

@ -108,11 +108,6 @@ fun InputAmount(
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(8.dp))
// Row(
// modifier = Modifier.align(Alignment.CenterHorizontally),
// verticalAlignment = Alignment.Bottom
// ) {
Text(
text = formatAmount(amount.ifEmpty { "0" }),
color = Color.LegacyRed,
@ -127,12 +122,7 @@ fun InputAmount(
modifier = Modifier.padding(end = 10.dp, bottom = 6.dp)
)
}
// }
Spacer(modifier = Modifier.height(14.dp))
Text(
text = supportingText,
color = Color.Gray,
@ -141,8 +131,6 @@ fun InputAmount(
)
}
}
//second container
Column(
modifier = Modifier
.fillMaxWidth()
@ -246,14 +234,15 @@ private fun formatAmount(value: String): String {
val groupedWholePart = "%,d".format(wholePart.toLongOrNull() ?: 0L)
if (!normalized.contains(".")) {
return groupedWholePart
return "$groupedWholePart.00"
}
val decimalPart = normalized.substringAfter(".", "")
return if (normalized.endsWith(".")) {
"$groupedWholePart."
"$groupedWholePart.00"
} else {
"$groupedWholePart.$decimalPart"
val padded = decimalPart.padEnd(2, '0').take(2)
"$groupedWholePart.$padded"
}
}

View File

@ -802,7 +802,14 @@ fun AppNavGraph(
}
private fun formatAmountForDisplay(amount: String?): String {
val normalizedAmount = amount.orEmpty()
val value = normalizedAmount.toLongOrNull() ?: return normalizedAmount.ifBlank { "0" }
return "%,d".format(value)
val raw = amount.orEmpty().trim()
if (raw.isBlank()) return "0.00"
if (raw.contains(".")) {
val whole = raw.substringBefore(".").ifEmpty { "0" }
val decimal = raw.substringAfter(".", "")
val grouped = "%,d".format(whole.toLongOrNull() ?: 0L)
return "$grouped.${decimal.padEnd(2, '0').take(2)}"
}
val value = raw.toLongOrNull() ?: return raw
return "%,d.00".format(value)
}