Skip to content

fix(normalizer): read the whole part of money with cents correctly - #597

Merged
remsky merged 2 commits into
remsky:masterfrom
lbarrosby:fix-money-negative-and-singular
Nov 13, 2026
Merged

remsky merged 2 commits into
remsky:masterfrom
lbarrosby:fix-money-negative-and-singular

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

When an amount has cents, _money in normalization/english.py builds the spoken whole part from int(math.floor(number)) and the bill word from plural(bill, count=number):

input before after
-$1.50 minus two dollars and fifty cents minus one dollar and fifty cents
-£3.75 minus four pounds and seventy-five pence minus three pounds and seventy-five pence
$1.05 one dollars and five cents one dollar and five cents
€1.20 one euros and twenty cents one euro and twenty cents

floor rounds a negative amount down, so every negative amount with cents was read one unit too high. inflect pluralizes for any count other than 1, so 1.05 always got the plural. Whole amounts (-$5, $1.00) take the other branch and were already right.

The cents branch now reads the sign on its own (int(-0.25) would drop it), uses int(abs(number)) for the words and the plural, and takes the cents from the absolute value. math is no longer used in the module, so its import is gone.

Testing

  • uv run pytest passes locally (API changes)
  • npm run test:web passes locally (web player changes)
  • New or changed behavior has a test
  • Ran in Docker (npm run cpu:up / gpu:up), for inference or docker changes
  • CHANGELOG.md entry, if users will notice the change

Five new CASES in api/tests/test_normalizer.py (the four rows above plus -$0.25, which keeps "minus zero dollars and twenty-five cents"). All five fail on master and pass with the fix. I ran test_normalizer.py, test_normalizer_contract.py and test_normalizer_properties.py (159 passed) in a small venv with the locked inflect 7.5.0, without torch or model weights, so I did not tick the full uv run pytest box. ruff check and ruff format --check are clean.

AI disclosure: written with the help of Claude Code, reviewed and tested by me.

lbarrosby and others added 2 commits November 12, 2026 21:18
The cents branch of _money took math.floor of the amount, so a negative
amount lost one more unit: -$1.50 was read as "minus two dollars and
fifty cents". It also pluralized the bill on the full amount, so $1.05
became "one dollars". Read the sign on its own, use the whole number of
units for the words and for the plural.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@remsky

remsky commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Thanks @lbarrosby, good fix and coverage.

Small nit: think this brings in duplicate bills handling at english.py:318, but it won't have any perf impact. Will give it a test and tidy in a follow-up if needed.

@remsky
remsky merged commit 455aaf9 into remsky:master Nov 13, 2026
4 checks passed
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.

2 participants