有线导致两个浮点数不同的结果 [英] Wired result in two float number different result
问题描述
大家好,
一旦我尝试获得不同的2个浮点数,我就会发现有线结果。以下是查询,
数据和结果,我累了。
在SalesInvoices表中有2 浮动列,一个如果 GrandTotal ,另一个是 RealAmountPaid 。
GrandTotal = 2306.28
RealAmountPaid = 2306.28
我写下如下查询来获取这两列中的不同列,
Hi All,
I find out wired result once i try to get the different in 2 float number. Here are the query ,
data and result which are i tired.
In SalesInvoices table have 2 float columns, one if GrandTotal and the other is RealAmountPaid.
GrandTotal =2306.28
RealAmountPaid= 2306.28
I write the query as below to get the different of these two columns,
SELECT GrandTotal, RealAmountPaid,(GrandTotal - RealAmountPaid) As NetDueAmount
FROM SalesInvoices
以下是我得到的有线结果
GrandTotal = 2306.28
RealAmountPaid = 2306.28
NetDueAmount = 4.54747350886464E-13
我发现其他数字结果是正确的。
eg.1
GrandTotal = 299.6
RealAmountPaid = 2 50
NetDueAmount = 49.6
GrandTotal = 1004.73
RealAmountPaid = 1004.73
NetDueAmount = 0
有没有人遇到过同样的问题?
如果您在我的查询或数据结构中发现任何错误,请指导我。
提前致谢,
Theingi
Here are the wired result what i got
GrandTotal =2306.28
RealAmountPaid = 2306.28
NetDueAmount = 4.54747350886464E-13
I found that the other number result are correct.
eg.1
GrandTotal =299.6
RealAmountPaid=250
NetDueAmount =49.6
GrandTotal =1004.73
RealAmountPaid=1004.73
NetDueAmount =0
Did anyone faced the same problem?
Kindly guide me if you found any error in my query or data structure.
Thanks in advance,
Theingi
推荐答案
您的查询很好,您选择的数据类型不是。
FLOAT不应该用于货币,也不能用于REAL。
你应该使用MONEY或DECIMAL。
Float使用科学近似和东西,它适用于采样和数学。
你无法改变你的行为。
http://msdn.microsoft.com/en-us/library/ms173773.aspx [ ^ ]
PS请注意,4.54747350886464E-13表示......
0.00000000000454747350886464
通过'科学近似'看看我的意思?
FLOAT和REAL很好,但不适合你的特殊问题。
我过去和你有同样的问题,只是我在一家餐馆测量了多少公斤玉米饼。
Your query is good, your selection of data types not.
FLOAT should not be used for currency, nor REAL.
You should use MONEY or DECIMAL.
Float uses scientific approximations and stuff, it is good for sampling and math.
You can't change that behaviour you're getting.
http://msdn.microsoft.com/en-us/library/ms173773.aspx[^]
PS Notice that 4.54747350886464E-13 means...
0.00000000000454747350886464
See what I mean by 'scientific approximations'?
FLOAT and REAL are good, but not for your particular problem.
I had the same problem as you in the past, only I was measuring how many kilos of tortillas were being used at a restaurant.
这篇关于有线导致两个浮点数不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!