Re: No feedback for executing a mathematical expression
P Kishor <[email protected]> Tue, 10 Mar 2020 09:08:33 +0100
| Newsgroups | gmane.comp.db.sqlite.general |
|---|---|
| Message-ID | <[email protected]> |
A very helpful and clear explanation to many of us not familiar with SQLite’s math idiosyncracies, or simply needing a refresher. Many thanks Keith. > On Mar 10, 2020, at 8:57 AM, Keith Medcalf <[email protected]> wrote: > > > On Tuesday, 10 March, 2020 01:22, Octopus ZHANG <[email protected]> wrote: > >> I try to run a simple math expression, but SQLite gives no feedback : > >> sqlite> select 99-(55/(30/57)); > >> Should I expect it to return nothing? > > It is returning something. It is returning NULL. > > sqlite> .nullvalue <NULL> > sqlite> select 99-(55/(30/57)); > <NULL> > sqlite> > > 99 - (55 / (30 / 57)) > > 30 / 57 -> 0 > > 55 / 0 -> NULL > > 99 - NULL -> NULL > > If you want the result of 30/57 to be a floating point number (ie, not zero), you need to have one of those numbers be floating point, after which each successive operation will be carried out in floating point rather than integer arithmetic. > > 30. / 57 == 30 / 57. == 30. / 57. -> 0.526315789473684 > > 55 / 0.526315789473684 -> 104.5 > > 99 - 104.5 -> -5.5 > _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users