SQL Server的除法精度

huangapple go评论94阅读模式
英文:

sql server division precision

问题

我有一个视图,我想要计算 columnA/columnB 的结果。这两列都是小数。然而,我得到的精度不够。我只能得到小数点后面的6位数,但我想要得到全部的小数位数。

例如,3163.82/240008.56 = 0.013182,但我想要得到 0.0131821131712969。
我尝试了使用 CAST 和 ROUND,但仍然得到相同的结果。

英文:

I have a view and I want to divide columnA/columnB. Both columns are decimals. However, I don't get the precision I need. I get only 6 values after the decimal point and I want to get all of them.

For example 3163.82/240008.56 = 0.013182 and I want to get 0.0131821131712969.
I tried CAST, ROUND and still I get the same result.

答案1

得分: 4

在进行除法运算之前,请先进行类型转换。类似于以下代码:

cast(3163.82 as decimal(30,20)) / 240008.56

链接:https://dbfiddle.uk/4c3SmjSB

英文:

Do cast before dividing. Something like

cast(3163.82 as decimal(30,20)) / 240008.56

https://dbfiddle.uk/4c3SmjSB

huangapple
  • 本文由 发表于 2023年8月8日 19:46:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定