为什么如果你进行这种转换你会改变结果? [英] why if you do this conversion you change the result?

查看:56
本文介绍了为什么如果你进行这种转换你会改变结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么如果你做

declare @p float='29545428.022495'

select cast(@p as numeric(17,9))



you获得这个?

29545428.022495002



请您解释这种类型的差异,并帮助我理解价值变化的原因?

谢谢你


you obtain this?
29545428.022495002

please can you explain the differece of this type and help me to understand why the value change?
thank you

推荐答案

你总是会在sql中的float \\\
umeric类型之间转换(c#中的double \decimal),因为float \ double类型不能保存您想要的确切数字,它包含一个接近您想要的数学表示。这允许它存储比它们的实际数量等价物(例如numeric \ decimal)更大的数字。如果数字精度对你至关重要,那么浮点数不是一个好的选择。
You'll always get slight differences converting between float\numeric types in sql (double\decimal in c#) because the float\double type doesn't hold the exact number you want, it holds a mathematical representation that is close to what you want. This allows it to store far greater\smaller numbers than their "actual number" equivalents like numeric\decimal. If numeric precision is crucial to you then floats are not a good choice.


这篇关于为什么如果你进行这种转换你会改变结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆