Live data from Hacker News

Never Use Floats for Money (2016)

husobee.github.io

11–20 of 41 posts

Re: Never Use Floats for Money (2016)

#14

I 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…

> and then hearing "Use floats for money. All of our customers do, and if we don't you'll create needless friction for them."

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)

#16
post #4

Great 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.

Same! Dates are one of the biggest sources of programmer error in my experience, and representing them as ints until they are rendered to a UI prevents a lot of it.

Re: Never Use Floats for Money (2016)

#17
post #4

Great 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.

Actually, using timestamps for all dates is a bit like using floats for currency. For many cases it doesn't matter, but you lose information.

Re: Never Use Floats for Money (2016)

#19

I 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…

[deleted]
Post reply on HN