From cbb63318941d7c997ae71f4f0a894eccf2cf9ed5 Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Sun, 26 Nov 2023 14:41:39 +0300 Subject: [PATCH] Fix fractional formatter --- .../core/ui/common/textfield/FormatterExtensions.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/FormatterExtensions.kt b/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/FormatterExtensions.kt index 8e05d594..7e37c864 100644 --- a/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/FormatterExtensions.kt +++ b/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/FormatterExtensions.kt @@ -59,10 +59,15 @@ fun String.formatExpression( return input.replace(Token.Digit.dot, formatterSymbols.fractional) } - // Only format integral part + // Fractional if (input.contains(Token.DisplayOnly.fraction)) { - val (integral, fraction) = input.split(" ") - return "${integral.formatNumber(formatterSymbols)} $fraction" + // Only format integral part + val splitFractional = input.split(" ") + if (splitFractional.size > 1) { + return "${splitFractional[0].formatNumber(formatterSymbols)} ${splitFractional[1]}" + } + // No integral part + return input } numbersRegex