Just remember however that you only have 53-bits of precision, so in floating point adding a "small" number (eg, 0.01) to a big number (1e16) the result will be 1e16 not 1.00000000000000001e16 whereas with scaled decimal the result will be precise and that unless special precautions are taken that the floating point sum of 1.0, 1e100, 1.0, -1e100 is 0, not 2.0, because the result is in the scale of the largest input, not the smallest.
--- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-----Original Message----- >From: sqlite-users [mailto:sqlite-users- >[email protected]] On Behalf Of Wout Mertens >Sent: Sunday, 16 December, 2018 07:55 >To: SQLite mailing list >Subject: Re: [sqlite] Question about floating point > >On Sat, Dec 15, 2018 at 7:13 PM Keith Medcalf <[email protected]> >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 >[email protected] >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

