开发者

SQLite calculations

I'm running into a rather simple problem and I can't determine whether the problem is my SQLite gui (tried 2 btw with same results) or SQLite itself. When I run the following

SELECT (30/24)-1 as 'calc'

I g开发者_如何学Pythonet 0 instead of the expected .25

Now obviously this is not my actual query but when it started getting the same result with actual numbers I got worried

Please let me know whether this is an SQLite issue or an issue with my SQLite Manager


You need to move from integer to floating arithmetic. E.g. change the 30 to 30.0 and you'll get your required result:

SELECT (30.0/24)-1 as 'calc'


It's because your query is rounding down to zero, as it's being cast implicitly to an Integer.

Have you tried explicitly casting your numbers/result to a decimal?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜