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 / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Division Error?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rhl - 24 Jul 2007 22:43 GMT
I just came across this weird division result with VB.NET.

2/3 = 0.66666666666666663

With VB6, I get

2/3 =0.666666666666667

Using the Windows Calculator results in
0.66666666666666666666666666666667

I'm sure I'm not the first one to notice this...what gives?

rhl
Scott M. - 24 Jul 2007 23:03 GMT
The differences are due to the math being done on different data types.

VB 6's, VB .NET's and Windows don't all have comprable data types.

>I just came across this weird division result with VB.NET.
>
[quoted text clipped - 10 lines]
>
> rhl
Patrice - 25 Jul 2007 17:43 GMT
Exact code ? I've got the same result than in VB6 with Debug.WriteLine(2 /
3)

Anyway, all those results are wrong and obviously you'll never be able to
display or even compute the correct result. More generally this is a well
know problem with "real" numbers.

You have several ways to workaround this depending on the problem you have
with this. You could use a better type (such as decimal) for increasing (and
possibly "guaranteed" precision), you could store this a a fraction etc...

--
Patrice

>I just came across this weird division result with VB.NET.
>
[quoted text clipped - 10 lines]
>
> rhl

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.