News for hackers. Stuff that matters.
Re:0.30000000000000004 by F-0X on Monday December 02, 2019 @04:57PM (#21687466)
Money is not as wierd as anyone might guess. I work on a financial application, and money is almost always just a BigDecimal with the scale set to 2 (and stored in a database as a bigint type or equivalent). When its not, its just a higher scale (for say, compound daily interest on small amounts for a significant period of time).
Re:0.30000000000000004 by blowski on Monday December 02, 2019 @05:16PM (#21687653)
How do you store Bitcoin?
Re:0.30000000000000004 by zelly on Monday December 02, 2019 @07:14PM (#21688568)
Bitcoin uses fixed-width unsigned integers. The smallest unit is 10^-8 of 1 Bitcoin, which is represented as just 1.
Re:0.30000000000000004 by blowski on Tuesday December 03, 2019 @03:52AM (#21690897)
I like this approach. Is it compatible with the parent comment?
Re:0.30000000000000004 by zelly on Tuesday December 03, 2019 @10:42AM (#21693276)
Yes, the parent approach is the same thing but with a decimal point added for convenience. The main thing is that the scale is fixed; it is effectively an integer count of 1s of the least significant index. It is impossible to truncate values or round upward and create money that didn't exist. This makes it perfect for representing actual money.