SQL Server Float data type calculation vs decimal

冷暖自知 提交于 2019-11-29 08:28:02

Float is accurate to 15 significant figures only (in SQL Server).

This is demonstrated by 1.52415693411713 E+17 where 1.52415693411713 (15 digits) is as accurate as you'll get. The final 020... after 152415693411713 with STR is made up is the resolution of floating point

To keep precision, don't use float. It is that simple. CAST to decimal if you want for calculation, but if you CAST back to float you are limited to 15 digits

See "What Every Computer Scientist Should Know About Floating-Point Arithmetic"

The last answer

152415692881907790.143935926652

is providing scale up to 12 decimal places because you have declared @z accordingly.

declare @z decimal (32,12)

The second parameter in this declaration is scale which is set to 12.

More on the this can be found at http://msdn.microsoft.com/en-us/library/ms187746.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!