2 ms·
You really want to use a decimal library for any serious financial math. And if you’re doing the math on tiny units of processing you’re going to want the preci
by Waterluvian 4y ago
You really want to use a decimal library for any serious financial math. And if you’re doing the math on tiny units of processing you’re going to want the precision and accuracy.
You don’t need to work in decimal cents. Many work in thousandths of a cent or smaller. But you want an infinite upper and lower bound. Even 64 bit integers only has so much upper range depending on how far you subdivide a penny. You also want the precision guarantees when you take those numbers and do more than just add or subtract them.
- pclmulqdq 4y agoWhy do you need an infinite upper bound for money? I agree that you need to do saturating arithmetic, but 2^64/10^8 dollars is about 10^10 dollars, which is the around the GDP of the US. A number that big is not going to show up in your billing system if you do everything correctly. With all numerical calculations, you need to be careful about losing precision on mathematical operations, so it's a good idea to think about things like this even if you use a decimal number system with a very wide dynamic range - it won't be very precise all the time.