Hacker News new | ask | show | jobs
by ddeokbokki 2314 days ago
> Sometimes being compatible is more important than being correct.

It's a simple conversion for the sake of precision. If you are dealing with money transactions, you should strive for precise values wherever and whenever possible.

1 comments

If your customers are already using floats, precision has already been lost. They're sending you data that already has floating-point round-off. If you then treat that as integer numbers of cents, you're adding additional round-off error by converting their 23 bits of binary precision to 2 digits of decimal precision. It's better to use the same format they do so that all floating-point error occurs within their systems, where it's known, has presumably been judged to be low-risk, and can be compensated for, rather than silently and unpredictably add new sources of error that your customers don't know about.
There is no source of errors in doing: bigint_value = float_value * 10^E if E else float_value float_value = bigint_value / 10^E if E else bigint_value

Obviously only convert to real numbers if you are doing operations on numbers in your system, otherwise keep in client format like you said.