Home > Database > Mysql Tutorial > How to Perform Accurate Floating-Point Division in SQLite?

How to Perform Accurate Floating-Point Division in SQLite?

Susan Sarandon
Release: 2024-12-15 00:17:13
Original
606 people have browsed it

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template