Home >Database >Mysql Tutorial >How to Perform Accurate Floating-Point Division in SQLite?
Performing Floating-Point Division in SQLite
When dividing integers in SQLite, the result is returned as an integer. This can be problematic if you want to calculate a real value. To resolve this issue, you can cast one of the numbers to a real number by multiplying it by 1.0.
For example, the following query returns an integer result:
sqlite> select totalUsers/totalBids from (select (select count(*) from Bids) as totalBids , (select count(*) from Users) as totalUsers) A; 1
To obtain the real value of the division result, multiply one of the numbers by 1.0:
sqlite> select totalUsers*1.0/totalBids from (select (select count(*) from Bids) as totalBids , (select count(*) from Users) as totalUsers) A; 0.5
The above is the detailed content of How to Perform Accurate Floating-Point Division in SQLite?. For more information, please follow other related articles on the PHP Chinese website!