3 ms·
I've always seen currencies multiplied by 100 to remove the need for floating point.
by trevor-e 2y ago
I've always seen currencies multiplied by 100 to remove the need for floating point.
- nijave 2y agoYeah, this seems like a common pattern. Not sure about currency with arbitrary place values though (like Bitcoin)
- deathanatos 2y agoI'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)
- akavi 2y agoThat's not quite a sufficient rule. Eg, 1 Bahraini Dinar is 1_000 Bahraini Fils.
- cateye 2y agoSome 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.
- kadoban 2y agoIf you use a higher constant, 10000 or 1000000 or something, you give yourself a good amount of more fleixibility.