为什么28.08在DataGridView中显示为28.080000000000002 [英] Why does 28.08 show up as 28.080000000000002 in DataGridView
问题描述
我很困惑。我在SQL Server Express数据库中有一个名为
Longitude的列。这是一个浮动。当我在DataGridView中查看表时,
一些数字,数据库中只有两位小数
显示* 15 *小数位并且是稍微偏离(在主题行的
示例中,大约2E-15)。
我没有对此专栏做任何操作。它只是运行一个存储的
过程,它在表上执行一个非常基本的SELECT。如果我在Management Studio Express中运行
存储过程,所有数字都会显示
罚款(只有两位小数)。
这里发生了什么?
谢谢,
-Dan
I''m baffled. I have a column in a SQL Server Express database called
"Longitude," which is a float. When I view the table in a DataGridView,
some of the numbers, which only have two decimal places in the database
show up with *15* decimal places and are ever so slightly off (in the
example in the subject line, by about 2E-15).
I''m not doing any operations on this column. It''s just running a stored
procedure which performs a pretty basic SELECT on the table. If I run
the stored procedure in Management Studio Express, all numbers show up
fine (just two decimal places).
What''s going on here?
Thanks,
-Dan
推荐答案
FLOAT是近似数据类型。如果你想要精确度,那么使用
适当的DECIMAL而不是FLOAT。
Daniel Manes < da ****** @ cox.netwrote in message
news:11 ********************** @ k58g2000hse .googlegr oups.com ...
FLOAT is an approximate data type. If you want precision, then use an
appropriate DECIMAL instead of FLOAT.
"Daniel Manes" <da******@cox.netwrote in message
news:11**********************@k58g2000hse.googlegr oups.com...
我很困惑。我在SQL Server Express数据库中有一个名为
Longitude的列。这是一个浮动。当我在DataGridView中查看表时,
一些数字,数据库中只有两位小数
显示* 15 *小数位并且是稍微偏离(在主题行的
示例中,大约2E-15)。
我没有对此专栏做任何操作。它只是运行一个存储的
过程,它在表上执行一个非常基本的SELECT。如果我在Management Studio Express中运行
存储过程,所有数字都会显示
罚款(只有两位小数)。
这里发生了什么?
谢谢,
-Dan
I''m baffled. I have a column in a SQL Server Express database called
"Longitude," which is a float. When I view the table in a DataGridView,
some of the numbers, which only have two decimal places in the database
show up with *15* decimal places and are ever so slightly off (in the
example in the subject line, by about 2E-15).
I''m not doing any operations on this column. It''s just running a stored
procedure which performs a pretty basic SELECT on the table. If I run
the stored procedure in Management Studio Express, all numbers show up
fine (just two decimal places).
What''s going on here?
Thanks,
-Dan
Daniel,
Float是一种近似的数据类型。在BOL中查找近似数字数据。
- 比尔
Daniel Manes < da ****** @ cox.netwrote in message
news:11 ********************** @ k58g2000hse .googlegr oups.com ...
Daniel,
Float is an approximate datatype. Lookup approximate numeric data in BOL.
-- Bill
"Daniel Manes" <da******@cox.netwrote in message
news:11**********************@k58g2000hse.googlegr oups.com...
我很困惑。我在SQL Server Express数据库中有一个名为
Longitude的列。这是一个浮动。当我在DataGridView中查看表时,
一些数字,数据库中只有两位小数
显示* 15 *小数位并且是稍微偏离(在主题行的
示例中,大约2E-15)。
我没有对此专栏做任何操作。它只是运行一个存储的
过程,它在表上执行一个非常基本的SELECT。如果我在Management Studio Express中运行
存储过程,所有数字都会显示
罚款(只有两位小数)。
这里发生了什么?
谢谢,
-Dan
I''m baffled. I have a column in a SQL Server Express database called
"Longitude," which is a float. When I view the table in a DataGridView,
some of the numbers, which only have two decimal places in the database
show up with *15* decimal places and are ever so slightly off (in the
example in the subject line, by about 2E-15).
I''m not doing any operations on this column. It''s just running a stored
procedure which performs a pretty basic SELECT on the table. If I run
the stored procedure in Management Studio Express, all numbers show up
fine (just two decimal places).
What''s going on here?
Thanks,
-Dan
Daniel Manes< da ****** @ cox.netwrote:
Daniel Manes <da******@cox.netwrote:
我很困惑。我在SQL Server Express数据库中有一个名为
Longitude的列。这是一个浮动。当我在DataGridView中查看表时,
一些数字,数据库中只有两位小数
显示* 15 *小数位并且是稍微偏离(在主题行的
示例中,大约2E-15)。
我没有对此专栏做任何操作。它只是运行一个存储的
过程,它在表上执行一个非常基本的SELECT。如果我在Management Studio Express中运行
存储过程,所有数字都会显示
罚款(只有两位小数)。
这里发生了什么?
I''m baffled. I have a column in a SQL Server Express database called
"Longitude," which is a float. When I view the table in a DataGridView,
some of the numbers, which only have two decimal places in the database
show up with *15* decimal places and are ever so slightly off (in the
example in the subject line, by about 2E-15).
I''m not doing any operations on this column. It''s just running a stored
procedure which performs a pretty basic SELECT on the table. If I run
the stored procedure in Management Studio Express, all numbers show up
fine (just two decimal places).
What''s going on here?
参见 http://www.pobox.com/~skeet/csharp/floatingpoint.html
作为参考,最接近的.NET加倍到28.08正好是
28.0799999999999982946974341757595539093017578125
-
Jon Skeet - < sk *** @ pobox.com>
如果回复小组,请不要给我发邮件
See http://www.pobox.com/~skeet/csharp/floatingpoint.html
For reference, the closest .NET double to 28.08 is exactly
28.0799999999999982946974341757595539093017578125
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
这篇关于为什么28.08在DataGridView中显示为28.080000000000002的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!