feat(presentation): add locale-aware number and currency formatting - #329
Merged
Conversation
Compose Resources does no Android-style escaping, so the %% in the string rendered literally as 100%%.
Amounts were built by hand with a fixed '.' separator, no grouping and the symbol always leading. Each platform now supplies only locale data (separators, grouping sizes, symbol and percent affixes) derived from formatter probes; the grouping and assembly stay in commonMain so every target renders identically and the logic is unit-testable. Currency symbol and fraction digits keep coming from the server's Currency, not from the locale, so a currency looks the same everywhere. Ties round half-up rather than half-to-even as kotlin.math.round does, which would render 0.125 as 0.12. Web must pass navigator.languages explicitly: an empty locale list makes Intl use the browser's UI language, not the content-language preference the rest of the app follows.
Replaces MoneyFormat, RateFormat and the private formatPercent, epsilon, roundTo and parseAmount copies, plus three DEFAULT_DECIMALS constants. Screens read the locale off a CompositionLocal through thin composable shims, so most call sites keep their shape; ViewModels that seed amount fields take NumberSymbols as a dependency, which also keeps their tests off the host locale. Balance signs move to formatSignedMoney instead of prefixing '+'/'−' by hand, the add-entry hero puts the symbol on whichever side the locale wants, and amount fields filter input and accept a pasted grouped amount.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes: #313