This type of thing coming from programmers really bothers me. Here is a more universal rule: Never say "never." Whether or not floating point numbers can be used depends on the context. If you are talking about an accounting system, core banking system, ERP, or similar transactional systems, then sure you probably should use integers not floats. However, if you're working on any financial model, like something as sim…
Never Use Floats for Money (2016)
31–40 of 41 posts
Re: Never Use Floats for Money (2016)
#32This type of thing coming from programmers really bothers me. Here is a more universal rule: Never say "never." Whether or not floating point numbers can be used depends on the context. If you are talking about an accounting system, core banking system, ERP, or similar transactional systems, then sure you probably should use integers not floats. However, if you're working on any financial model, like something as sim…
It can't be worth any microscopic performance benefit to not just be safe/precise and substitute a decimal datatype in 99% of cases. Something crazy like HFT might be an exception, or if it's just a quick excel sheet. Otherwise it's still a perfectly good rule of thumb to keep money in decimal types if you're writing code.
Modeling (including financial modeling) requires transcedental functions and real numbers.
Re: Never Use Floats for Money (2016)
#33Re: Never Use Floats for Money (2016)
#34I remember hearing this back when I worked on financial software for hedge funds (2005ish), adjusting our product so it represented currencies as integer numbers of cents, taking the change to my boss (the company CEO), and then hearing "Use floats for money. All of our customers do, and if we don't you'll create needless friction for them." Ran into it more recently when doing cryptocurrency market analytics. Bitcoi…
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.
Re: Never Use Floats for Money (2016)
#35Fun Fact: Microsoft Excel uses double precision floating point numbers. Much of the world's numbers are run through Excel. I feel like some people have probably just ended up using the same floats themselves, just so that their boss's spreadsheet agrees with their numbers... https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft...
Re: Never Use Floats for Money (2016)
#36I remember hearing this back when I worked on financial software for hedge funds (2005ish), adjusting our product so it represented currencies as integer numbers of cents, taking the change to my boss (the company CEO), and then hearing "Use floats for money. All of our customers do, and if we don't you'll create needless friction for them." Ran into it more recently when doing cryptocurrency market analytics. Bitcoi…
> 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.
Re: Never Use Floats for Money (2016)
#37Use a rational type :)
That all gets thrown out the window when somebody really wants an exchange rate of pi for god knows why, but satisfying every real number is impossible, and satisfying every computable number exposes you to things like the halting problem, so having a system that just supports rationals seems like a good compromise.
Re: Never Use Floats for Money (2016)
#38on the backend I have python's exquisite Decimal() which covers all bases and is base-10
how would one guarantee that precision when you have to serialize it into json and that's gonna become a normal double in JS?
Re: Never Use Floats for Money (2016)
#39Re: Never Use Floats for Money (2016)
#40How do I properly handle Money on the web frontend side? on the backend I have python's exquisite Decimal() which covers all bases and is base-10 how would one guarantee that precision when you have to serialize it into json and that's gonna become a normal double in JS?
[0]https://frontstuff.io/how-to-handle-monetary-values-in-javas...