Add locale-aware digit grouping to displayed amounts
Adds groupDigits(), a display-only formatter that inserts the current locale's digit-grouping separators into an amount's integer part (e.g. "1,000,000.5" in en-US vs "1.000.000,5" in de-DE, where the roles of "," and "." are swapped, or hi-IN's irregular "12,34,567"). Delegates to each platform's native locale APIs (java.text.NumberFormat/DecimalFormatSymbols, NSNumberFormatter/NSLocale, Intl.NumberFormat with BigInt for arbitrary precision) rather than reimplementing grouping rules, and never touches the canonical '.'-decimal strings the rest of the app parses and stores. Applied via a Compose VisualTransformation (BTC/Sats/fiat/manual-rate fields, plus the read-only rate display) and, on the native SwiftUI screen, by re-deriving the field's displayed text on every change. Also made input parsing locale-aware: sanitizeDecimalInput now recognizes the locale's own decimal separator (e.g. what a locale-aware decimal keypad sends), not just "." — with a stricter rule on the SwiftUI side specifically, since its single text buffer re-feeds the grouped display back through sanitize, so a "." can be grouping noise there rather than a decimal point. The exceeds-max-supply warning's "21,000,000 BTC" is no longer baked into the localized string with hardcoded grouping; it's substituted in at runtime via groupDigits so the link-detection text always matches exactly, in every locale. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QpjMKWGoiT5aJBzhxvXkwp
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package xyz.tyiu.satsprice.domain
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.text.NumberFormat
|
||||
import java.util.Locale
|
||||
|
||||
actual fun localizedGroupedInteger(digits: String): String =
|
||||
NumberFormat.getIntegerInstance(Locale.getDefault()).format(BigInteger(digits))
|
||||
|
||||
actual fun localizedDecimalSeparator(): String =
|
||||
DecimalFormatSymbols.getInstance(Locale.getDefault()).decimalSeparator.toString()
|
||||
Reference in New Issue
Block a user