Safe number parsing | En kodare

submited by
Style Pass
2023-01-26 08:30:07

At a previous job we had an incident once with too loose number parsing. This is my advice on how to parse numbers when it matters. First I’m going to describe how our existing number parsing failed (after running successfully in production for 14 years!), then how we solved it.

The configuration for decimal separator was incorrect for one file format for one customer. This caused numbers like 123,45 to be parsed as 12345. That’s two orders of magnitude. Quite bad, but that’s not the bad part. 123.456.789,12 would be parsed as 123.45678912. These broken numbers trickled through various systems causing trouble for our customers.

This configuration choice was made by many different people, many times a day. This mistake was made many times, and caught and fixed many times before there were big consequences for our customers. But eventually your luck runs out.

Problem 1: These mistakes were not considered a flaw of the system, but as human error. This type of thinking leads to a dangerous situation where humans must always be flawless and if they are not it’s the humans who are to blame. This thinking guarantees failure.

Leave a Comment