Updated on 2026-08-14
This commit is contained in:
parent
3d33a141d3
commit
b00bbf5f22
1 changed files with 12 additions and 4 deletions
|
|
@ -20,13 +20,20 @@ class InputNumberFormatter(
|
|||
val thousandsSeparator = symbols.groupingSeparator
|
||||
val decimalSeparator = symbols.decimalSeparator
|
||||
|
||||
if (text.startsWith("0") && text.length > 1 && text[1] != decimalSeparator) {
|
||||
val lastChar = text.last()
|
||||
val trimmedText = if (text.isNotEmpty() && (lastChar == thousandsSeparator || lastChar == POINT_SEPARATOR)) {
|
||||
text.dropLast(1) + decimalSeparator
|
||||
} else {
|
||||
text
|
||||
}
|
||||
|
||||
if (trimmedText.startsWith("0") && trimmedText.length > 1 && trimmedText[1] != decimalSeparator) {
|
||||
return "0"
|
||||
}
|
||||
|
||||
val filteredChars = text.replace(thousandsSeparator.toString(), "").filterIndexed { index, c ->
|
||||
val isOneOrZeroPoint = c == decimalSeparator && index != 0 && text.count { it == decimalSeparator } <= 1
|
||||
val isIndexPointIndex = c == decimalSeparator && index != 0 && text.indexOf(decimalSeparator) == index
|
||||
val filteredChars = trimmedText.replace(thousandsSeparator.toString(), "").filterIndexed { index, c ->
|
||||
val isOneOrZeroPoint = c == decimalSeparator && index != 0 && trimmedText.count { it == decimalSeparator } <= 1
|
||||
val isIndexPointIndex = c == decimalSeparator && index != 0 && trimmedText.indexOf(decimalSeparator) == index
|
||||
c.isDigit() || isIndexPointIndex || isOneOrZeroPoint
|
||||
}
|
||||
// If dot is present, take first digits before decimal and first decimals digits after decimal
|
||||
|
|
@ -64,5 +71,6 @@ class InputNumberFormatter(
|
|||
|
||||
companion object {
|
||||
private const val TEXT_CHUNK_THOUSAND = 3
|
||||
private const val POINT_SEPARATOR = '.'
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue