英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论