Skip to content

Use the standard decimal context in the rounding guide - #1530

Open
AmanBoronbaev wants to merge 1 commit into
python-babel:masterfrom
AmanBoronbaev:docs-decimal-rounding-context
Open

AmanBoronbaev wants to merge 1 commit into
python-babel:masterfrom
AmanBoronbaev:docs-decimal-rounding-context

Conversation

@AmanBoronbaev

Copy link
Copy Markdown

The number-formatting guide still warns that the standard decimal module can use a different rounding context from Babel. Current Babel imports the standard module directly. The example also uses primary prompts inside a with block, so it fails when pasted into an interactive interpreter.

Use decimal.localcontext() to round 123.99 down to 123, then show that the same value formats as 124 after the previous context is restored. The four interactive examples and all 144 tests in tests/test_numbers.py passed with the project's CLDR data.

AI assistance: OpenAI Codex updated the examples and ran them against this checkout.

This branch has not been deployed

No deployments
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