[#1139] Malformed pattern for ICU DecimalFormat

- This handles possible malformed format pattern exceptions in Zashi, but the proper solution needs to be provided within the SDK. See  #1315.
- Closes #1139
This commit is contained in:
Honza Rychnovský 2023-12-21 17:40:59 +01:00 committed by GitHub
parent 90c982ac2a
commit c901a63d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -2,6 +2,7 @@
package cash.z.ecc.sdk.extension
import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.model.MonetarySeparators
import cash.z.ecc.android.sdk.model.PercentDecimal
import java.math.RoundingMode
@ -16,6 +17,10 @@ private fun preparePercentDecimalFormat(): DecimalFormat =
DecimalFormat().apply {
val monetarySeparators = MonetarySeparators.current()
val localizedPattern = "##0${monetarySeparators.decimal}00"
applyLocalizedPattern(localizedPattern)
runCatching {
applyLocalizedPattern(localizedPattern)
}.onFailure {
Twig.error(it) { "Failed on applying localized pattern" }
}
roundingMode = RoundingMode.HALF_UP
}