Discussion:
Can you calculate 110 - 101.85
(too old to reply)
Seyfullah ÝZMÝRLÝ
2010-01-05 16:36:45 UTC
Permalink
can you calculate 110 - 101.85
is it 8.15000000000001

is there any idea, how to fix this problem?

do not prefer to Format the value
Ralph
2010-01-05 17:08:38 UTC
Permalink
Post by Seyfullah ÝZMÝRLÝ
can you calculate 110 - 101.85
is it 8.15000000000001
is there any idea, how to fix this problem?
Yes, format the display of the internal number to reflect the scale or
precision you want shown.
Post by Seyfullah ÝZMÝRLÝ
do not prefer to Format the value
Then you are out of luck.

"(Complete) Tutorial to Understand IEEE Floating-Point Errors"
http://support.microsoft.com/kb/42980

"What Every Computer Scientist Should Know About Floating-Point Arithmetic"
http://docs.sun.com/source/806-3568/ncg_goldberg.html

You can also find numerous other sources on the web that explain these kinds
of issues with floating point numbers, and provide suggestions on how to
work around them.

-ralph
Seyfullah ÝZMÝRLÝ
2010-01-06 08:14:11 UTC
Permalink
No it was an example of my problem,
VB does the same problem with toomany different numbers...

So i have a big problem with vb mathematic,

There ara toomany variant that i am using in the code,
How can you prefer to guess "if a result is wrong" ?
for example:

dim a ,b,c
a = InputBox("Enter a number")
b = InputBox("Enter another number")
c = a - b ' or c = a * b or c = a/b
' if user gives the 12.45678 for a number and 34.3 fro b number
'you were format the value like c = format(c,"#,0")
' so user smiles, and laughs your code
' user tells that you can not do the operation...

Please some body help
Post by Ralph
Post by Seyfullah ÝZMÝRLÝ
can you calculate 110 - 101.85
is it 8.15000000000001
is there any idea, how to fix this problem?
Yes, format the display of the internal number to reflect the scale or
precision you want shown.
Post by Seyfullah ÝZMÝRLÝ
do not prefer to Format the value
Then you are out of luck.
"(Complete) Tutorial to Understand IEEE Floating-Point Errors"
http://support.microsoft.com/kb/42980
"What Every Computer Scientist Should Know About Floating-Point Arithmetic"
http://docs.sun.com/source/806-3568/ncg_goldberg.html
You can also find numerous other sources on the web that explain these kinds
of issues with floating point numbers, and provide suggestions on how to
work around them.
-ralph
Ralph
2010-01-06 14:35:11 UTC
Permalink
Post by Seyfullah ÝZMÝRLÝ
No it was an example of my problem,
VB does the same problem with toomany different numbers...
So i have a big problem with vb mathematic,
There ara toomany variant that i am using in the code,
How can you prefer to guess "if a result is wrong" ?
dim a ,b,c
a = InputBox("Enter a number")
b = InputBox("Enter another number")
c = a - b ' or c = a * b or c = a/b
' if user gives the 12.45678 for a number and 34.3 fro b number
'you were format the value like c = format(c,"#,0")
' so user smiles, and laughs your code
' user tells that you can not do the operation...
Variants have nothing to do with it.

It is not a problem with "VB Math". It is a simple fact of how floating
point numbers work in computers.

As my reply and the URLs I posted didn't seem to help, and since this is NOT
a VB bug, I suggest you re-post your question to the
microsoft.public.vb.general.discussion newsgroup. More VBers hang out there
and you will be better served.

-ralph
Seyfullah ÝZMÝRLÝ
2010-01-06 14:49:11 UTC
Permalink
Thank you Ralph,
i am trying the microsoft.public.vb.general newsgroup
Nobody
2010-01-06 17:44:38 UTC
Permalink
That's normal. If you need absolute precision, you need to look for "math
symbolic engine", which keeps fractions in their symbolic form, like "1 /
3", and doesn't reduce it to 0.33333.

INFO: Visual Basic and Arithmetic Precision
http://support.microsoft.com/kb/279755
David Kaye
2010-01-07 10:13:00 UTC
Permalink
Post by Seyfullah ÝZMÝRLÝ
No it was an example of my problem,
VB does the same problem with toomany different numbers...
So i have a big problem with vb mathematic,
Some numbers simply can't be accurately represented in binary, just as some
numbers can't be represented accurately in decimal. Try representing the
fraction 2/3 accurately in decimal. You can't. Well, binary has similar
problems, but with other numbers.

Loading...