473,407 Members | 2,359 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.

Why do I get this Result in (655.55-655)*100 =54.9999999999955 ??

655.5555-655 =0.555500000000052
(655.55-655)*100 =54.9999999999955
Visual C# 2003

Jul 21 '05 #1
3 1346
Amir Parsa wrote:
655.5555-655 =0.555500000000052
(655.55-655)*100 =54.9999999999955
Visual C# 2003


Because of floating point errors. Use decimal if you require precision
math instead.

See Jon Skeet's great article
http://yoda.arachsys.com/csharp/floatingpoint.html
for details

HTH,
Stefan
Jul 21 '05 #2
Amir Parsa wrote:
655.5555-655 =0.555500000000052
(655.55-655)*100 =54.9999999999955
Visual C# 2003


This is not C# specific. And is typical :). I don't think you can do
anything about that. Try rounding to required precision.

Regards,
Grzegorz Kaczor
Jul 21 '05 #3

"Amir Parsa" <Amir Pa***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
655.5555-655 =0.555500000000052
(655.55-655)*100 =54.9999999999955
Visual C# 2003


As stated by the other responders, this is the result of real number
approximation in a binary machine. Found in Java, C++, etc. as well as C#.
Here are some articles that you may find interesting:

http://www.math.grin.edu/~stone/cour...EEE-reals.html

http://www.prosperosoftware.co.uk/so...PSPvFloat.html

http://www.scit.wlv.ac.uk/cbook/chap4.float.html

The Decimal type in the .NET Framework is your best choice for max precision
without doing extra work.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 21 '05 #4

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

Similar topics

2
by: Börni | last post by:
Hi, me again ;-) So i have this code: <?php $db = new db(); $sql = "SELECT id FROM contentobject_attribute WHERE contentobject_id=2 AND contentclassattribute_id=1"; $result =...
7
by: Yannick Turgeon | last post by:
Hello all, I tryed to simplify the problem as much as possible. I'll start with the DDL: ---------------------------------- CREATE TABLE #MyTable( NoID INT, Type CHAR,...
2
by: Dylan | last post by:
thanks for any comments. Here's the code //------------------------------------------------------------------ #include <iostream> class Base { protected: virtual int GetValue()=0;
3
by: Amir Parsa | last post by:
655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003
4
by: choudharymv | last post by:
I have 1 table "Progress" P_no b_no status build_date ---------------------------------------------------------------- 25 1 First_slab ...
9
by: Petr Vileta | last post by:
Hi, I'm new here and excuse me if this question was be here earlier. I have a simple code <html><body> <?php <?php $link = mysql_connect("localhost", "user", "password") or die("Grr: " ....
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
0
by: anandnalya | last post by:
Hi, I've designed this small application. I want to know if there are some chances of race conditions, deadlocks or memory leaks in it. Please give your comments. The problem is that I need to...
1
by: phpuser123 | last post by:
I just implemented the following script with regerence to the internet and got as result 20... long val=10; long g=(byte)(val << 1); System.out.println(g); I am...
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: 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
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
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.