Updated on 2026-08-14
This commit is contained in:
parent
86c748685e
commit
21bf5f1ead
11 changed files with 76 additions and 34 deletions
|
|
@ -10,9 +10,9 @@ package com.tangem.core.ui.utils
|
|||
*/
|
||||
fun getValidatedNumberWithFixedDecimals(text: String, decimals: Int): String {
|
||||
val filteredChars = text.filterIndexed { index, c ->
|
||||
c.isDigit()
|
||||
|| (c == '.' && index != 0 && text.indexOf('.') == index)
|
||||
|| (c == '.' && index != 0 && text.count { it == '.' } <= 1)
|
||||
val isOneOrZeroPoint = c == '.' && index != 0 && text.count { it == '.' } <= 1
|
||||
val isIndexPointIndex = c == '.' && index != 0 && text.indexOf('.') == index
|
||||
c.isDigit() || isIndexPointIndex || isOneOrZeroPoint
|
||||
}
|
||||
// If dot is present, take first 3 digits before decimal and first decimals digits after decimal
|
||||
return if (filteredChars.count { it == '.' } == 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue