Skip to content

fix(normalizer): read money with more than two decimals as a decimal number - #599

Merged
remsky merged 1 commit into
remsky:masterfrom
lbarrosby:fix-money-sub-cent-decimals
Nov 13, 2026
Merged

remsky merged 1 commit into
remsky:masterfrom
lbarrosby:fix-money-sub-cent-decimals

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

_money in normalization/english.py treats every fractional part as cents: it takes the digits after the dot as an integer and reads them as the coin. That only works for one or two decimals. Prices with more decimals are common (US fuel prices, per-token or per-unit rates, crypto):

input before after
Gas is $3.499 a gallon three dollars and four hundred and ninety-nine cents three point four nine nine dollars
$0.0012 per token zero dollars and twelve cents zero point zero zero one two dollars
-$1.005 minus one dollar and five cents minus one point zero zero five dollars

The $0.0012 case is the worst one, because the amount gets 10,000 times bigger when read aloud.

When the matched number has more than two decimals and is not a whole amount, the amount is now read as a decimal number followed by the plural bill, the same way $1.5 million is already read. The words come from the matched digits rather than from the float, so small values never go through scientific notation. Whole amounts with trailing zeros (£2.000) still take the existing branch and stay "two pounds". One and two decimals ($5.5, $5.50, $1.05) are unchanged.

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

Four new CASES in api/tests/test_normalizer.py (the three rows above plus £2.000). The three rows fail on master and pass with the fix. I ran test_normalizer.py, test_normalizer_contract.py and test_normalizer_properties.py in a small venv with the locked inflect 7.5.0, without torch or model weights (178 passed; the two test_normalizer_redos.py cases that import the full text processor need torch and fail the same way on master), 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.

…number

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@remsky
remsky merged commit 1083bb0 into remsky:master Nov 13, 2026
4 checks passed
@remsky

remsky commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Looks good, thanks @lbarrosby

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