# A Simple Money-Parsing Rule Misread 16 of 24 Test Amounts

Source: https://www.digiparser.com/blog/money-parsing-benchmark

[See all posts](/blog)

Last updated on October 27, 2026

# A Simple Money-Parsing Rule Misread 16 of 24 Test Amounts

Research

Data quality

Financial data

[![Pankaj Patidar](https://avatars.githubusercontent.com/u/17493609?v=4)

Pankaj Patidar

@thepantales



](https://x.com/thepantales)

![A Simple Money-Parsing Rule Misread 16 of 24 Test Amounts](/research/money-parsing-benchmark/results.png)

Executable research / 27 October 2026

**A cleanup rule preserved every digit in 24 constructed money strings. It still returned the wrong amount in 16 cases.** All 24 outputs were finite numbers, so a simple "is this numeric?" check would have accepted every failure.

DigiParser ran two literal JavaScript conversion rules against a fixed stress set: four locale-based numeric bodies, each with six controlled sign or currency forms. The result is a test of those rules on those inputs. It gives developers a small, reusable regression set for a large design mistake: treating punctuation and signs as disposable formatting.

**Preserving the digits is not the same as preserving the money.** A decimal separator determines scale. A minus sign determines direction. A parenthesis can carry the meaning that a cleanup rule deletes.

Read the [results](#two-rules-very-different-failures), inspect the [three failure mechanisms](#three-ways-the-amount-changed), or [download the complete test](#download-and-reuse).

## Two rules, very different failures

We tested two deliberately simple rules, with no locale-aware validation added:

1.  **Numeric prefix:** apply JavaScript's `parseFloat` directly to the string.
2.  **Strip and convert:** remove everything except ASCII digits, the ASCII hyphen and the period, then apply JavaScript's `Number` conversion.

The second rule looks more accommodating: it removes currency labels and grouping marks. In this experiment, that flexibility hid incorrect values behind successful numeric conversion.

On small screens, swipe the table to see every result. The table region also accepts keyboard focus.

Measured outputs on the same 24 constructed valid inputs

Rule

Correct amount

Wrong finite amount

Rejected as non-finite

Numeric prefix

0

12

12

Strip and convert

8

16

0

"Wrong" means a finite numeric output that differs from the fixture's declared expected amount. "Rejected" means a non-finite output; it does not mean that either one-line rule supplied a useful error message. The [full CSV](/research/money-parsing-benchmark/results.csv) records every input, output and classification.

![24 constructed inputs per rule: numeric prefix produced zero correct, 12 wrong and 12 rejected results; strip and convert produced eight correct, 16 wrong and zero rejected results.](/research/money-parsing-benchmark/results.png)

These counts describe a balanced stress set, not the frequency of failures in production invoices. The useful finding is the demonstrated failure mechanism: a rule can keep all the digits and still lose the amount.

## Three ways the amount changed

All four numeric bodies represent the positive amount 123,456.78 under their declared formatting context: `123,456.78` for en-US, `123.456,78` for de-DE, `123 456,78` for fr-FR, and `1,23,456.78` for en-IN. The French grouping character is a narrow no-break space, U+202F.

The [Unicode CLDR number-pattern guidance](https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns) explains decimal and grouping symbols, Indian grouping and accounting negative patterns. Those conventions make a useful stress-test basis. Our six wrappers are explicit test grammar, rather than a claim that each wrapper is the native display convention of every locale.

Actual strip-and-convert outputs; expected values shown in dot-decimal notation

Input

Expected

Actual output

Failure

`123.456,78`

123456.78

123.45678

1,000 times smaller

`123 456,78`

123456.78

12345678

100 times larger

`(123,456.78)`

−123456.78

123456.78

Sign reversed

**Decimal meaning disappeared.** Removing the German decimal comma leaves the grouping period in place. Removing both the French grouping space and decimal comma produces an integer 100 times the expected amount. The digits remain in order in both cases.

**Negative meaning disappeared.** Parentheses and the Unicode minus sign `−` are removed by the strip rule. For the US and Indian numeric bodies, those forms become positive amounts. An ASCII hyphen `-` survives. Visually similar signs therefore produce different financial results.

**Numeric success concealed semantic failure.** Every strip-and-convert output was finite. Checking only the output type or finiteness could not distinguish its eight correct results from its 16 wrong results.

A number is a data type. A correct amount is a claim about meaning.

## Why the prefix rule fails differently

JavaScript's [official parseFloat specification](https://tc39.es/ecma262/multipage/global-object.html#sec-parsefloat-string) permits conversion of the longest valid numeric prefix. That is useful behavior for a general conversion function. It is an incomplete contract for a money field.

In our test, `parseFloat` reads `123,456.78` as `123`, and `123.456,78` as `123.456`. A currency prefix, an opening parenthesis or a Unicode minus sign produces no valid leading numeric prefix in these fixtures. The result is non-finite rather than an amount.

The lesson is not that a language function is broken. The application must decide whether the entire field matches an accepted monetary format before trusting a conversion. A function that stops partway through a field cannot make that decision on its own.

## Missing money must stay missing

We also ran five separate invalid-input controls. Strip and convert accepted four as finite numbers: an empty string, `USD`, `Invoice 42`, and `12.34 due 56`. Only `12.34.56` was rejected. Numeric prefix accepted the last two strings that start with digits and rejected the other three.

The empty string and `USD` both became zero after stripping. This follows the [ECMAScript string-to-number conversion rule](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tonumber-applied-to-the-string-type): an empty string converts to positive zero. A missing amount had acquired a financial value.

These five controls are excluded from the 24-input result table. They answer a separate question: does the rule refuse values outside the declared money grammar?

For an invoice workflow, our recommendation is firm: **missing, zero and invalid must remain distinct states.** A blank total should enter a review path, rather than quietly becoming a valid zero-value bill.

## Give every money field a contract

Before a captured amount reaches a spreadsheet or a configured accounting system, define what the field accepts. Our recommended contract has five parts:

1.  **Formatting context.** Specify accepted decimal and grouping conventions. If the context is unknown and the string is ambiguous, request clarification instead of guessing from one punctuation mark.
2.  **Sign grammar.** Define accepted minus characters and whether parentheses mean a negative amount. Reject conflicting signs and unexpected characters before normalization.
3.  **Currency and scale.** Keep the currency with the value. Define precision and rounding for the destination; this experiment fixes USD and does not perform currency conversion.
4.  **Whole-field validation.** Require one complete accepted amount, with no leftover labels, second amounts or malformed grouping. Preserve missing and invalid states.
5.  **Traceable output.** Retain the original string, the applied format rule and the normalized amount. For exact financial calculations, use an appropriate decimal or integer-minor-unit representation with an explicit rounding policy.

A small team can use the fixture set to check a spreadsheet import. An integration team can add it to automated tests and extend it with formats that its own suppliers actually use. Neither team needs to treat a higher acceptance count as better quality.

For practical capture and export steps, see our [invoice data extraction guide](/blog/invoice-data-extraction) and [PDF to CSV guide](/blog/pdf-to-csv). This benchmark concerns the amount interpretation between capture and use; its inputs already contain the intended characters.

## How we ran these tests

On 27 October 2026, we generated numeric bodies with `Intl.NumberFormat` for en-US, de-DE, fr-FR and en-IN, using the value 123456.78 and exactly two fractional digits. We crossed each body with six explicit forms: bare positive, ASCII-minus negative, Unicode-minus negative, accounting-parentheses negative, USD prefix and USD suffix. That creates 24 fixtures: 12 positive and 12 negative.

We froze the strings, expected decimal values and expected minor-unit integers in a downloadable JSON file. We then executed the two rules in Node.js v24.19.0, V8 13.6.233.17-node.51, ICU 78.3 and CLDR 48.0. The current [Unicode UTS #35 Numbers, version 49](https://www.unicode.org/reports/tr35/tr35-79/tr35-numbers.html) was inspected for context; the frozen strings reflect the recorded runtime's CLDR version.

A valid-fixture output was correct only if it was finite and equal to the declared expected decimal converted to a JavaScript number. We applied no tolerance, rounding repair or locale inference. Digit preservation compared the ordered ASCII digits before and after stripping. All 24 strip-rule inputs passed that narrower check.

This controlled design deliberately includes challenging formats at equal weights. It isolates conversion behavior; it does not estimate format prevalence, OCR accuracy, customer outcomes or any document product's performance. Extend the fixed set before using it to judge a different grammar or implementation.

See the two exact conversion rules

```
// Numeric prefix
parseFloat(raw)
```

The downloaded runner executes these rules directly, classifies every result and records Unicode code points so that spaces and minus characters can be inspected.

## Download and reuse

**Run the benchmark. Challenge your own parser.**  
[All 58 result rows (CSV)](/research/money-parsing-benchmark/results.csv)  
[Frozen fixtures and expected values (JSON)](/research/money-parsing-benchmark/fixtures.json)  
[Executable benchmark runner](/research/money-parsing-benchmark/run-benchmark.mjs) - [Fixture generator](/research/money-parsing-benchmark/generate-fixtures.mjs)  
[Runtime and result summary](/research/money-parsing-benchmark/summary.json) - [Complete results (JSON)](/research/money-parsing-benchmark/results.json)  
[Reusable chart (SVG)](/research/money-parsing-benchmark/results.svg) - [Run instructions and reuse terms](/research/money-parsing-benchmark/README.txt)

Suggested citation: **"In DigiParser's 24-fixture money-parsing stress test, a strip-and-convert rule preserved every digit but returned 16 incorrect amounts."** Link to this page and retain the constructed-input scope when quoting the finding. Original fixtures, results and chart are available under CC BY 4.0; the two scripts are available under MIT terms in the accompanying instructions.

* * *

[See all posts](/blog)

Automate recurring documents next: [supplier invoice parser](/solutions/invoice-parser), [customer purchase order parser](/solutions/purchase-order-parser), and [extract data from PDF](/solutions/extract-data-from-pdf) hub.

## Transform Your Document Processing

Start automating your document workflows with DigiParser's AI-powered solution.

[Start Free Trial](https://app.digiparser.com/auth/join)[Schedule Demo](/contact)