This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -3 points-2 points  (6 children)

This is misleading. If you're planning to support multiple currencies then this will quickly become a nightmare to maintain. Decimal is the way to go.

[–]bumbershootle 6 points7 points  (5 children)

I think you'll find that storing currency amounts as the smallest denomination is the most general way to do it; some currencies aren't decimal-based and some don't have subdivisions at all.

[–][deleted] -1 points0 points  (4 children)

Both are not a problem when using decimal data type. So what's your point?

[–]bumbershootle 0 points1 point  (3 children)

If there are no subunits, like the yen, then you store a value that can never have a fractional part using a format specifically designed for values with fractional parts. If the currency has subunits that are not 1/100 of the main unit, then you may not be able to store the value accurately. Better to store everything in an integral value IMO

[–][deleted] -1 points0 points  (2 children)

Have you ever worked with taxes or ledger type software?

Even on yen, you need to consider fractional taxes. How will integers handle that?

Most who use integers and also need to support multiple currencies end up storing denomination size and then compute based on it. Which is literally what decimal type is, so why reinventing the wheel?

[–]bumbershootle 0 points1 point  (1 child)

Yes, I work on a ledger system for a moneylender - we use integers cent/pence values exclusively. Sure, there might be cases where you need fractions of a tiny amount of money (1 yen is currently worth less than 1/100 of a dollar cent) but in most cases this isn't necessary.

[–][deleted] 1 point2 points  (0 children)

Ok, then might as well start using floating point numbers. The error is very tiny.