保存在SQL Server中的浮点值 [英] Save float values in SQL Server

查看:155
本文介绍了保存在SQL Server中的浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Web应用程序,并要保存在SQL服务器浮点数或双精度格式的一些数字。

I have a simple web app , and want to save some numbers of Float or Double format in SQL server.

但有一个问题,当我尝试节省123.66,在表我看到存储123.6600003662109。

but there is a problem , when I try to save 123.66 , In Table I see 123.6600003662109 stored.

如何ND为什么我的浮点数时改变,可节省DB?如何解决这个问题?

How nd why my float number changed when save on DB? how can I fix this error?

感谢

推荐答案

您'再不是的真正的试图挽救123.66,因为你不能代表准确123.66为float或双。该数据库是更准确的比你用来保存数据,这就是全部。

You're not actually trying to save 123.66, because you can't represent 123.66 exactly as a float or double. The database is saving the data more accurately than you're used to, that's all.

如果你想准确地保存的小数的数字,用在小数键入

If you want to save decimal numbers accurately, use the decimal type.

请参阅我上的浮动小数点浮动小数点类型多信息。

See my articles on floating binary point and floating decimal point types for more info.

这篇关于保存在SQL Server中的浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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