Skip to content

Locale-aware number formatting in Distance/Temperature (fixes ungrouped odometer)#38

Open
MrL0 wants to merge 1 commit into
schmidtwmark:mainfrom
MrL0:fix/locale-aware-measurement-grouping
Open

Locale-aware number formatting in Distance/Temperature (fixes ungrouped odometer)#38
MrL0 wants to merge 1 commit into
schmidtwmark:mainfrom
MrL0:fix/locale-aware-measurement-grouping

Conversation

@MrL0

@MrL0 MrL0 commented Jun 28, 2026

Copy link
Copy Markdown

What this does

Distance.Units.format and Temperature.Units.format build a NumberFormatter but never set numberStyle, so it defaults to .none — which applies no grouping separator and a hardcoded . decimal separator. Two user-visible consequences:

  • Odometer / range render ungrouped: a 19,500 mi odometer shows as 19500 instead of 19,500.
  • Half-degree Celsius (the maximumFractionDigits = 1 path) shows a hardcoded period: 22.5°C even in locales that use a comma.

Setting formatter.numberStyle = .decimal makes both locale-aware. maximumFractionDigits is 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.

value before en-US de-DE fr-FR
19,500 mi odometer 19500 mi 19,500 mi 19.500 mi 19 500 mi
22.5 °C 22.5°C 22.5°C 22,5°C 22,5°C

Testing

swift test291 tests pass. Added testDistanceUnitsFormatGroupsThousands, 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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant