Why can a pass rate computed from two counts turn into zero?

With integer operands SQLite can use integer division, truncating toward zero. A real-valued operand preserves the fractional part.

SQLite example and interpretation

Two successes in five requests give 0.4. Casting after integer division cannot recover the discarded fraction.

SELECT 2/5,CAST(2 AS REAL)/5;

Result [[0, 0.4]]

中文

两个整数计数相除,为什么通过率变成零?

SQLite 在两个操作数都是整数时可执行整数除法,结果向零截断。让一个操作数为实数即可保留小数部分。

SQLite 示例与适用条件

两次成功除以五次请求应为 0.4。若在整数除法之后才转换类型,丢失的小数无法恢复。

SELECT 2/5,CAST(2 AS REAL)/5;

结果 [[0, 0.4]]

References / 参考来源

Keep reading / 继续阅读