|
|
|
|
|
by racingmars
1482 days ago
|
|
Financial calculations need to be done with fixed-point, not floating-point, arithmetic. Floating-point can't store the exact value of most fractional numbers, and especially over many transactions for many customers the floating-point errors will accumulate. You need basic addition and subtraction to always be exact (e.g. $15.27 + $91.31 needs to come out as $106.58, not $106.5799999999999999999998), and for operations that may have remainders beyond your desired number of digit precision, you need deterministic rounding or other rules to handle it. If you're ever writing any code that handles money, DO NOT use just naively use float and double types in your code! |
|