Hacker News new | ask | show | jobs
by trevor-e 780 days ago
I've always seen currencies multiplied by 100 to remove the need for floating point.
4 comments

If you use a higher constant, 10000 or 1000000 or something, you give yourself a good amount of more fleixibility.
Some currencies use more than 2 decimal places. For instance, the currencies of Algeria, Bahrain, Iraq, Jordan, Kuwait, Libya, and Tunisia are subdivided into 3 decimals.
That's not quite a sufficient rule. Eg, 1 Bahraini Dinar is 1_000 Bahraini Fils.
Yeah, this seems like a common pattern. Not sure about currency with arbitrary place values though (like Bitcoin)
I'm not sure what you mean by "arbitrary place values" with Bitcoin; if you are implying it's infinitely divisible, it isn't. You'd do the same trick with Bitcoin: represent it as an integer¹. The value 1 is 1 sat, or 0.00000001 BTC.

¹(where you need to; otherwise, I'd use some fixed point type if my language supports it)