473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Division Error?

rhl
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

Jul 24 '07 #1
2 1238
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.
"rhl" <ra******@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
>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

Jul 24 '07 #2
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
"rhl" <ra******@gmail.coma écrit dans le message de news:
11*********************@z24g2000prh.googlegroups.c om...
>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

Jul 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Artemisio | last post by:
I am a non programmer who just started with Python. So far I love it. I would appreciate if you could help me fix this error I get taking this exercise: count= 0 sum= 0.0 number= 1 print...
6
by: bart van deun | last post by:
Hello, i have a problem with a division by zero fault in my report trough a query... this is the expression in the query: Name: Sum(IIF(=0,0,/)) what is wrong with this expression?
3
by: John C Kirk | last post by:
I've come across an odd situation, where doing a floating point division produces different results for the same numbers. Basically, there are 4 ways to run this application: A) Debug build,...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
2
by: subnunciation | last post by:
i know, this shouldnt be a conundrum right? one just shouldnt divide by zero. but this is suddenly happening *all over* my site. after chasing the error here and there, i simplified things down to:...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
9
by: PengYu.UT | last post by:
Hi, The usually integer division will round the result to the biggest integet smaller than the float version division.For example, 10/3 = 3. I'm wondering if there is any easy way to round it...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
94
by: krypto.wizard | last post by:
Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and...
1
by: youjay | last post by:
I've been out of perl for a while, so I am starting from scratch. I have a small applet which scans a set of directories, getting information from some files in each one, and displaying selected...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.