提问人:Timur Shtatland 提问时间:2/7/2023 更新时间:2/7/2023 访问量:57
通过将其中一个操作数转换为非整数来防止整数除法
Preventing integer division by casting one of the operands as non-integer
答:
0赞
Timur Shtatland
2/7/2023
#1
正如手册所说,转换其中一个操作数(分子或分母)就足以防止整数除法。不需要同时铸造两者:
select 2 / 4; -- 0
select 2::numeric / 4; -- 0.50000000000000000000
select 2 / 4::numeric; -- 0.50000000000000000000
select 2::numeric / 4::numeric; -- 0.50000000000000000000
另请参见:
它们有 2 个铸件,而只需要 1 个铸件:
评论
select 1/2::numeric ; 0.50000000000000000000