Never Use Floats for Money (2016)
11–20 of 41 posts
Re: Never Use Floats for Money (2016)
#12A real life example: in the R language, this statement resolves to FALSE
> 74.20+153.20==227.40
[1] FALSERe: Never Use Floats for Money (2016)
#13Re: Never Use Floats for Money (2016)
#14I 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…
Until a competent customer doesn't, then you've got to explain to them why your calculations are intentionally wrong, never a good look. Regulatory bodies also tends to want the correct decimal numbers.
Re: Never Use Floats for Money (2016)
#15Re: Never Use Floats for Money (2016)
#16Great advice on going for the lowest (cents) so you can work with integers. I do something similar with dates on all my apps where I go for ints in the database and always save unix timestamps. I can't stand dates unless I'm working with timestamps.
Re: Never Use Floats for Money (2016)
#17Great advice on going for the lowest (cents) so you can work with integers. I do something similar with dates on all my apps where I go for ints in the database and always save unix timestamps. I can't stand dates unless I'm working with timestamps.
Re: Never Use Floats for Money (2016)
#18the perennial stackoverflow question -> https://stackoverflow.com/questions/3730019/why-not-use-doub... A real life example: in the R language, this statement resolves to FALSE > 74.20+153.20==227.40 [1] FALSE
Re: Never Use Floats for Money (2016)
#19I 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…
Re: Never Use Floats for Money (2016)
#20program: #include
using namespace std;
int main(int argc, char argv) { float s = 165 * 1.40; cout output: ./floats 231