Skip to content

Add international number format setting#94

Open
bitcoin3us wants to merge 2 commits intoMicroPythonOS:mainfrom
bitcoin3us:add-number-format-setting
Open

Add international number format setting#94
bitcoin3us wants to merge 2 commits intoMicroPythonOS:mainfrom
bitcoin3us:add-number-format-setting

Conversation

@bitcoin3us
Copy link
Copy Markdown
Contributor

Summary

  • Adds a system-wide "Number Format" dropdown to the Settings app for choosing decimal and thousands separators
  • New NumberFormat utility class (follows the TimeZone pattern) that any app can import via from mpos import NumberFormat
  • NumberFormat.format_number(value, decimals) formats ints and floats using the user's preferred locale
  • 7 presets: US/UK, Europe, French, Swiss, Tech, and two no-separator variants
  • 14 unit tests covering all formats, edge cases, and fallback behavior

Available formats

Preset Example
US/UK 1,234.56
Europe 1.234,56
French 1 234,56
Swiss 1'234.56
Tech 1_234.56
No separator (dot) 1234.56
No separator (comma) 1234,56

Usage by apps

from mpos import NumberFormat
NumberFormat.format_number(1234567)       # "1,234,567" (default US)
NumberFormat.format_number(1234.56, 2)    # "1,234.56"

Test plan

  • Run tests/unittest.sh tests/test_number_format.py — all 14 tests pass
  • Launch desktop, open Settings → "Number Format" dropdown appears between Timezone and Auto Start App
  • Select different formats → preference persists in config.json
  • Verify default (US/UK) matches existing behavior

🤖 Generated with Claude Code

Richard Taylor and others added 2 commits March 27, 2026 16:14
The WebServer import chain (mpos/__init__.py → webserver.py →
webrepl_http.py) requires the _webrepl C module which is only
available on ESP32 builds. This causes an ImportError on desktop/Unix
systems, preventing the entire mpos package from loading.

Wrap the import in try/except so desktop builds can still run.
main.py already has a similar guard around WebServer.auto_start().

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add a system-wide number format preference to the Settings app,
allowing users to choose their preferred decimal and thousands
separators. Follows the TimeZone pattern with a NumberFormat
utility class that any app can import.

Available formats:
- 1,234.56 (US/UK)
- 1.234,56 (Europe)
- 1 234,56 (French)
- 1'234.56 (Swiss)
- 1_234.56 (Tech)
- 1234.56 / 1234,56 (No thousands separator)

New files:
- lib/mpos/number_format.py — NumberFormat class with format_number()
- tests/test_number_format.py — 14 unit tests

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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