diff --git a/shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt b/shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt index 5255a54843..21206cf2fd 100644 --- a/shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt +++ b/shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt @@ -11,7 +11,7 @@ import kotlin.math.abs const val MILLION = 1_000_000 const val BILLION = 1_000_000_000 -const val HUNDREDOFTHOUSAND = 100000 +const val THOUSAND = 1_000 class FormatMoneyUseCase @Inject constructor( private val features: Features, @@ -24,14 +24,14 @@ class FormatMoneyUseCase @Inject constructor( private val withDecimalFormatter = DecimalFormat("###,###.00", DecimalFormatSymbols(locale)) suspend fun format(value: Double, shortenAmount: Boolean): String { - when (abs(value) >= HUNDREDOFTHOUSAND && shortenAmount) { + when (abs(value) >= THOUSAND && shortenAmount) { true -> { val result = if (abs(value) >= BILLION) { String.format(locale, "%.2fb", value / BILLION) } else if (abs(value) >= MILLION) { String.format(locale, "%.2fm", value / MILLION) } else { - String.format(locale, "%.2fk", value / HUNDREDOFTHOUSAND) + String.format(locale, "%.2fk", value / THOUSAND) } return result } diff --git a/shared/ui/core/src/test/java/com/ivy/ui/FormatMoneyUseCaseTest.kt b/shared/ui/core/src/test/java/com/ivy/ui/FormatMoneyUseCaseTest.kt index 776548f345..5ac42e742c 100644 --- a/shared/ui/core/src/test/java/com/ivy/ui/FormatMoneyUseCaseTest.kt +++ b/shared/ui/core/src/test/java/com/ivy/ui/FormatMoneyUseCaseTest.kt @@ -28,70 +28,70 @@ class FormatMoneyUseCaseTest { val expectedOutput: String ) { ENG_SHOW_DECIMAL( - amount = 1000.12, + amount = 1_000.12, showDecimal = true, shortenAmount = false, locale = Locale.ENGLISH, expectedOutput = "1,000.12" ), ENG_HIDE_DECIMAL( - amount = 1000.12, + amount = 1_000.12, showDecimal = false, shortenAmount = false, locale = Locale.ENGLISH, expectedOutput = "1,000" ), GERMAN_SHOW_DECIMAL( - amount = 1000.12, + amount = 1_000.12, showDecimal = true, shortenAmount = false, locale = Locale.GERMAN, expectedOutput = "1.000,12" ), GERMAN_HIDE_DECIMAL( - amount = 1000.12, + amount = 1_000.12, showDecimal = false, shortenAmount = false, locale = Locale.GERMAN, expectedOutput = "1.000" ), - ENGLISH_100K_SHORT_AMT( - amount = 130000.10, + ENGLISH_1K_SHORT_AMT( + amount = 13_000.10, showDecimal = true, shortenAmount = true, locale = Locale.ENGLISH, - expectedOutput = "1.30k" + expectedOutput = "13.00k" ), ENGLISH_MILLION_SHORT_AMT( - amount = 1230000.10, + amount = 1_230_000.10, showDecimal = true, shortenAmount = true, locale = Locale.ENGLISH, expectedOutput = "1.23m" ), ENGLISH_BILLION_SHORT_AMT( - amount = 1233000000.10, + amount = 1_233_000_000.10, showDecimal = true, shortenAmount = true, locale = Locale.ENGLISH, expectedOutput = "1.23b" ), - GERMAN_100K_SHORT_AMT( - amount = 130000.10, + GERMAN_1K_SHORT_AMT( + amount = 13_000.10, showDecimal = true, shortenAmount = true, locale = Locale.GERMAN, - expectedOutput = "1,30k" + expectedOutput = "13,00k" ), GERMAN_MILLION_SHORT_AMT( - amount = 1230000.10, + amount = 1_230_000.10, showDecimal = true, shortenAmount = true, locale = Locale.GERMAN, expectedOutput = "1,23m" ), GERMAN_BILLION_SHORT_AMT( - amount = 1233000000.10, + amount = 1_233_000_000.10, showDecimal = true, shortenAmount = true, locale = Locale.GERMAN,