473,385 Members | 1,342 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,385 software developers and data experts.

How do I make my computer unstupid?

JAM
I tell my computer a math problem (19.98-20.00) and it gives me a wako answer
(0.01999999999999996) what is wrong with it?
Jun 19 '06 #1
5 1005
"JAM" <JA*@discussions.microsoft.com> schrieb:
I tell my computer a math problem (19.98-20.00) and it gives me a wako
answer
(0.01999999999999996) what is wrong with it?


Nothing is wrong. This behavior is by design.

Binary floating point and .NET
<URL:http://www.yoda.arachsys.com/csharp/floatingpoint.html>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 19 '06 #2
bob
Jam,

I don' know much about arithmetic, but I can think of a lot of "stupid"
answers to your question, such as: To make your computer unstupid,
don't unfix it!

Good luck.

JAM wrote:
I tell my computer a math problem (19.98-20.00) and it gives me a wako answer
(0.01999999999999996) what is wrong with it?


Jun 20 '06 #3

a computer is not a human :-)

from a computers point of view the answer is completely valid

computers work with the binary system humans work with the decimal system

so to get a human expected answer you should convert the values to the
decimal system and then perform your math

(CType(19.98, Decimal) - CType(20.0, Decimal)
regards

Michel Posseth


"JAM" wrote:
I tell my computer a math problem (19.98-20.00) and it gives me a wako answer
(0.01999999999999996) what is wrong with it?

Jun 20 '06 #4

this is a nice article that explains the subject clearly

http://support.microsoft.com/default...b;en-us;214118

note that in VB.net we have the decimal datatype now that solves this issue
however it comes with a prize and that is resources ( speed, memory )

regards

Michel Posseth [MCP]
"JAM" wrote:
I tell my computer a math problem (19.98-20.00) and it gives me a wako answer
(0.01999999999999996) what is wrong with it?

Jun 20 '06 #5
M.Posseth,
I would recommend:

Dim d As Decimal = 19.98D - 20.0D

Which causes the 19.98 & 20.0 to be Decimal literals & not Double literals.

Being Decimal literals saves you from converting the values to Decimal at
run time...

At the very least it makes the expression easier to read ;-)

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"M. Posseth" <MP******@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
|
| a computer is not a human :-)
|
| from a computers point of view the answer is completely valid
|
| computers work with the binary system humans work with the decimal system
|
| so to get a human expected answer you should convert the values to the
| decimal system and then perform your math
|
| (CType(19.98, Decimal) - CType(20.0, Decimal)
|
|
| regards
|
| Michel Posseth
|
|
|
|
| "JAM" wrote:
|
| > I tell my computer a math problem (19.98-20.00) and it gives me a wako
answer
| > (0.01999999999999996) what is wrong with it?
Jun 21 '06 #6

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

Similar topics

25
by: tnrABC | last post by:
The approximately 100 books below are for sale. Mostly a selection of mathematics (numerical analysis mostly), computing science (graphics, ai, programming techniques, theory, compilers, operating...
5
by: z. f. | last post by:
i need to get the computer name from an aspx page. i use System.Windows.Forms.SystemInformation.ComputerName() and it's working fine, but in second thought, it might not be recomended to use the...
0
by: Daylor | last post by:
hi. i have app that im developing in my computer with vs.net 2003 (offcourse). now, this app is running in other computer in the local intranet. in the other computer i dont have vs.net installed...
0
by: py | last post by:
I am trying to execute a batch script on a remote computer. The batch script looks like: @echo off start c:\python24\python.exe c:\a_script.py Here's the setup: Computer A (my computer),...
0
by: Paul Brady | last post by:
I volunteer at a youth ministry agency and help them with their student database. They have two computers, both running Windows XP. Both have Office 2002 installed without Access, except that...
2
by: subsanta | last post by:
My computer has so many problems and ive looked around on the internet and ive managed to fix some of them. I know that i have a few viruses on my computer, but i cant get rid of them, in one case i...
0
by: masalamod | last post by:
http://www.cextube.com/search.php? search=computer++languages&submit=Video+Search http://www.cextube.com/search.php? search=computer++languages&submit=Video+Search ...
0
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media....
4
by: =?Utf-8?B?Qm9iQWNoZ2lsbA==?= | last post by:
Hi, I am using Visual Studio 2003. After moving my project to a new development computer my project compiles and works on the new development computer but the program will not work when I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.