473,804 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Basic calculation returns incorrect values

We're having a lot of problems getting visual studio to calculate even the
most basic arithmetic correctly.

For example:

Dim MyValue AS Double = 2.155 * 100

This should give me 215.5 right? Wrong. It gives me 215.49999999999 9999997

Change it to 1.155, it works. 3.155 it works. 2.155 it doesn't work.
We've found several values that don't seem to work correctly. I'm staggered
at this, we're trying to develop accounts based systems and yet visual
studio can't even multiply an item by 100 correctly?! It's not like I'm
doing anything complicated!

Has anyone else come across this and is there some kind of hot fix or patch
that can be applied to sort this out?

We've already been having problems with the round function in .net 1.1 and
had to write our own. The above problem occurs in 1.1 and 2.

Thanks in advance...
Oct 9 '06 #1
3 1386
Dale Reed wrote:
Dim MyValue AS Double = 2.155 * 100

This should give me 215.5 right? Wrong. It gives me
215.49999999999 9999997
Welcome to the "wonderful" world of floating point computing.

For more information on the reasons for the above-mentioned problem, please
see:

http://www.lahey.com/float.htm

or

http://docs.sun.com/source/806-3568/ncg_goldberg.html

Ebbe
Oct 9 '06 #2
I doubt there's a hot fix for it; the problem, in essence, is that .Net
doesn't know that (215.5 * 100) is an "easier" sum than (214.9871 *
99.31048) - because for a computer, it isn't.

If the latter was wrong by 0.0000000000000 003 you'd be hard pressed to
notice. You only notice the specific case because humans think in base
10.

That's an aside though, and not very useful. If you need to know that
your numbers are accurate, avoid floating points. Stick to longs and
divide 'em at the end. That's generally how you are recommended to
store money values in databases, too, for exactly the same reason -
floating point arithmetic is not 100% accurate, and accounting
departments are.
Dale Reed wrote:
We're having a lot of problems getting visual studio to calculate even the
most basic arithmetic correctly.

For example:

Dim MyValue AS Double = 2.155 * 100

This should give me 215.5 right? Wrong. It gives me 215.49999999999 9999997

Change it to 1.155, it works. 3.155 it works. 2.155 it doesn't work.
We've found several values that don't seem to work correctly. I'm staggered
at this, we're trying to develop accounts based systems and yet visual
studio can't even multiply an item by 100 correctly?! It's not like I'm
doing anything complicated!

Has anyone else come across this and is there some kind of hot fix or patch
that can be applied to sort this out?

We've already been having problems with the round function in .net 1.1 and
had to write our own. The above problem occurs in 1.1 and 2.

Thanks in advance...
Oct 9 '06 #3
why trivial calc.exe in windows calculate 2.155*100 right but .NET doesn't?

"Flinky Wisty Pomm" <Pa********@gma il.comwrote in message
news:11******** *************@c 28g2000cwb.goog legroups.com...
>I doubt there's a hot fix for it; the problem, in essence, is that .Net
doesn't know that (215.5 * 100) is an "easier" sum than (214.9871 *
99.31048) - because for a computer, it isn't.

If the latter was wrong by 0.0000000000000 003 you'd be hard pressed to
notice. You only notice the specific case because humans think in base
10.

That's an aside though, and not very useful. If you need to know that
your numbers are accurate, avoid floating points. Stick to longs and
divide 'em at the end. That's generally how you are recommended to
store money values in databases, too, for exactly the same reason -
floating point arithmetic is not 100% accurate, and accounting
departments are.
Dale Reed wrote:
>We're having a lot of problems getting visual studio to calculate even
the
most basic arithmetic correctly.

For example:

Dim MyValue AS Double = 2.155 * 100

This should give me 215.5 right? Wrong. It gives me
215.4999999999 99999997

Change it to 1.155, it works. 3.155 it works. 2.155 it doesn't work.
We've found several values that don't seem to work correctly. I'm
staggered
at this, we're trying to develop accounts based systems and yet visual
studio can't even multiply an item by 100 correctly?! It's not like I'm
doing anything complicated!

Has anyone else come across this and is there some kind of hot fix or
patch
that can be applied to sort this out?

We've already been having problems with the round function in .net 1.1
and
had to write our own. The above problem occurs in 1.1 and 2.

Thanks in advance...

Oct 9 '06 #4

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

Similar topics

5
3323
by: Michael Hagstrom | last post by:
Good Day - I have written a form which collects input for a fare calculation. The form collects the following: 1) Departure or Destination Group (1,2,or 3) 2) Number of Adults 3) Number of Children aged 4 to 12 4) Number of Children under age 4
10
1952
by: Michael G | last post by:
double A = floor((2447297.0 - 122.1)/365.25); i get differing results. It varies between 6699 and 6700. The correct answer is 6699. The 6700 result really throws the entire group of calculations off. Any suggestions welcome. Thanks Mike
9
1462
by: BaWork | last post by:
I'm using the following code to calculate order amount in a payment form for Authorize.net: (Assume book_copies = 1 and ship_country = United States) book_copies = request ("book_copies") product_price = 16.95 If ship_country = "United States" then ship_amount = 3.99
6
5301
by: jimfortune | last post by:
In: http://groups.google.com/group/comp.databases.ms-access/msg/60d7faa790c65db1 james.ea...@gmail.com said: :Ok, I've answered the first half of my own question. From a MSDN :article, I can now use the following to reference the last primary :key's values: :
4
3766
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The calculation is very simple. The calculation is done in an underling query if I can call it a query or I should call it a SQL statement. It looks like a query but it is not saved as the query. The calculation in that query is very simple - ExtendedPrice:*....
28
2666
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
1
6381
by: `Zidane Tribal | last post by:
it would appear that using the command 'crc("data")' from the String::CRC returns incorrect results (although, they are at least consistently incorrect). for example, this script..... #!/usr/bin/perl -w use strict; use String::CRC; print "crc: " . crc($ARGV) . " " . length($ARGV) . "\n";
11
2249
by: CrostonScottish | last post by:
I am having a few difficulties calculating values in my report with the sql code that i am using. It is made up of two parts: 1: (This bit is ok) A text box has the control source set as : *10)+(*9))]. This returns the value i expect when i test it. The problem is: 2: When i set the control source of another text box to take the value from text box 40 above and perform the calculation below it returns a spurious value: /(+)]
2
2759
by: Will | last post by:
Hi, I need to handle blank values in a query calculation. I have 636 records at the moment but when I sum over these records the blank fields are not returned. I have looked around here and on Access help and the Nz function seems to be the way forward. I am summing over 6 fields, all or none of which may contain values. The expression syntax I have used is as follows:
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.