Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

Why does 28.08 show up as 28.080000000000002 in DataGridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Manes - 09 Jan 2007 21:11 GMT
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
Erland Sommarskog - 09 Jan 2007 23:37 GMT
> 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,
[quoted text clipped - 8 lines]
>
> What's going on here?

float is an approamite datatype. It consists of a 53-bit mantissa and a
nine-bit exponent. That permits us to store a very broad range of
numbers. From 1E310 to 1E-310. The price is that far from all decimal
numbers can be represented exactly.

When a floating-point number is presented, it appears that different
applications are more or less zealous to show the decimals. If you were
to look at that column from Query Analyzer, the query tools that came with
SQL 2000, you would probably see that random noise at the end. QA shows
more decimals than Mgmt Studio does.

What is the best suggestion for your case I don't know, but you should
probably ask in a newsgroup where DataGridView is popular.

Signature

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.