That is why integer money amounts have a value/scale pair instead of mantissa/exponent. I don't expect you would be given change in the dimension of 1 "zimba" if you need 100 trillion to pay for a tank of gas.
The principle behind money = v * 10 ^ -s is just the same as float = m * 2 ^e, but avoids the rounding inherent in transforming from base 2 to base 10. -----Ursprüngliche Nachricht----- Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im Auftrag von Wout Mertens Gesendet: Sonntag, 16. Dezember 2018 15:55 An: SQLite mailing list <sqlite-users@mailinglists.sqlite.org> Betreff: [EXTERNAL] Re: [sqlite] Question about floating point On Sat, Dec 15, 2018 at 7:13 PM Keith Medcalf <kmedc...@dessus.com> wrote: > > >And yet ... here we are. The post which started this thread summed > >currency amounts and reached a total of 211496.25999999992 . > > >Yes, you can say 'that would have been rounded before it was > >printed'. But then you're into the old questions: do you round at > >every step, or only at the end ? Do you round or truncate ? Where > >does the fraction go ? etc. etc.. > > You apply half-even rounding (not elementary school 4/5 rounding) only > for display (output) and never round intermediates. The "fraction" > does not exist ... Though if you do 4/5 rounding rather than half-even > rounding the accumulated errors will amount to quite a sum. > TIL, thanks! I'd also like to point out a problem with integer money: inflation. For USD it's been OK so far, but imagine having to handle the Zimbabwean Dollar, which ended up having 100 trillion dollar notes. Good way to overflow your integers. With floating point, that's not a problem. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___________________________________________ Gunter Hick | Software Engineer | Scientific Games International GmbH | Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 1 80100 - 0 May be privileged. May be confidential. Please delete if not the addressee. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users