Locale-aware number formatting in Distance/Temperature (fixes ungrouped odometer)#38
Open
MrL0 wants to merge 1 commit into
Open
Locale-aware number formatting in Distance/Temperature (fixes ungrouped odometer)#38MrL0 wants to merge 1 commit into
MrL0 wants to merge 1 commit into
Conversation
…ure format() NumberFormatter defaulted to .none, which applies no grouping separator and a hardcoded '.' decimal separator. A 19,500 mi odometer rendered as "19500", and half-degree Celsius showed "22.5°C" even in comma-decimal locales. Set numberStyle = .decimal on both formatters so output follows the user's locale; maximumFractionDigits is still set afterward, so whole-number distances and Fahrenheit stay integer.
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.
What this does
Distance.Units.formatandTemperature.Units.formatbuild aNumberFormatterbut never setnumberStyle, so it defaults to.none— which applies no grouping separator and a hardcoded.decimal separator. Two user-visible consequences:19500instead of19,500.maximumFractionDigits = 1path) shows a hardcoded period:22.5°Ceven in locales that use a comma.Setting
formatter.numberStyle = .decimalmakes both locale-aware.maximumFractionDigitsis still set afterward, so whole-number distances and Fahrenheit stay integer-only.Because everything funnels through these two shared formatters, this fixes the odometer/range everywhere they appear (in-app, widget, Live Activity, Watch + complications, Trip view) with no call-site changes. It matters beyond the US — BetterBlue supports Hyundai US/CA/EU and Kia US/EU, and EU + French-Canada users use period/space grouping.
19500 mi19,500 mi19.500 mi19 500 mi22.5°C22.5°C22,5°C22,5°CTesting
swift test— 291 tests pass. AddedtestDistanceUnitsFormatGroupsThousands, which asserts grouping happens without pinning a specific separator, so it stays locale-independent across CI. Existing format assertions are unaffected (their values are < 1000, where no grouping appears).Drafted with AI assistance; verified locally with
swift test.