以下のSQL問合せでは、異なる結果が返されます。 精度は、元のクエリとケース3のコメントなしで異なります。 理由は何ですか?私は2014年SQL - 小数点以下を切り捨てる場合
declare @d1 decimal(20, 15), @d2 decimal(20, 15), @d3 decimal(20, 15), @d4 decimal(20, 15)
set @d1 = 22.0
set @d2 = 22.0
set @d3 = 1.00000
set @d4 = 7.0
select
case when (1 > 0) then @d1/@d4
when (2 > 0) then @d2/@d4
when (3 > 0) then @d2/(@d4 * @d3)
end
--Results:
--Without case 3 commented: 3.142857
--With case 3 commented: 3.142857142857142857
は、floatを使用してみてください。 –
@KeithJohnHutchison:浮動小数点は正確ではありません。 – Pred
@KeithJohnHutchison質問は*なぜこれが起こるのですか?そしてbtw:FLOATは - ほとんどの場合 - 何かが避けなければならないもの... – Shnugo