3 ms·
A lot of financial firms use an integer of the smallest indivisible unit of currency wherever possible (stripe is one). This has the handy property that string
by erpellan 7y ago
A lot of financial firms use an integer of the smallest indivisible unit of currency wherever possible (stripe is one). This has the handy property that string and numeric representations are identical so no risk of being flipped into scientific notation by some layer. That happens more often than you’d think.
FX is a different world. Spot FX trading systems are fully automated and compute rates to 5 DP. That was 15 years ago, I don’t know if it’s more now. Large Yen amounts can come worryingly close to the limits of precision.
I once watched a colleague trying to persuade a roomful of people to stop using floats. The demo showed what happens to 0.1 + 0.1 + 0.1. The answer was not 0.3. I’m not sure they believed him. Some of them are probably still writing software for your bank!
- mrunkel 7y agoFor shits and giggles: $ python3 Python 3.7.4 (default, Sep 7 2019, 18:27:02) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print (0.1 + 0.1 + 0.1) 0.30000000000000004 $ irb 2.5.1 :001 > print 0.1 + 0.1 + 0.1 0.30000000000000004 => nil Chrome browser console: > 0.1 + 0.1 + 0.1 < 0.30000000000000004 $ php <?php echo 0.1 + 0.1 + 0.1; 0.3
- samatman 7y agoIs this because PHP is correct, or is it because PHP rounds reprs at a different level of precision?