473,473 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

adding and subtracting in double

public class Test {
public static void main(String args[]) {
double d1 = 20000.01;
double d2 = 10000.01;
double d3 = d1 - d2;
System.out.println(d3);
}
}

why does the above code return 9999.999999999998.

Is there any way to make it return 10000;

Nischal
Jul 17 '05 #1
1 7197
"Nischal Topno" <tn******@yahoo.com> wrote in message
news:5a**************************@posting.google.c om...
public class Test {
public static void main(String args[]) {
double d1 = 20000.01;
double d2 = 10000.01;
double d3 = d1 - d2;
System.out.println(d3);
}
}

why does the above code return 9999.999999999998.

Is there any way to make it return 10000;

Yes. Round it. See
http://www.mindprod.com/jgloss/floatingpoint.html
Jul 17 '05 #2

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

Similar topics

0
by: Danny Winslow | last post by:
I get an unexpected result when I add two negative numbers in PHP on SPARC/Solaris 8. The same program works fine on Intel/Linux. I'm using PHP 4.3.1 on both systems. Here is my program,...
10
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
5
by: surrealtrauma | last post by:
the requirement is : Create a class called Rational (rational.h) for performing arithmetic with fractions. Write a program to test your class. Use Integer variables to represent the private data...
4
by: dixie | last post by:
If I had a table that could give a value to each letter in the alphabet, say from 1 for A to 26 for Z, would there be a simple way of adding up the total numerical value for a string of letters. ...
2
by: Landen | last post by:
I am wanting to replicate a linux feature that I can't seem to find anywhere in windows as an addin or program. If anyone is familiar with linux, if you right click on a folder or file, you get the...
10
by: Guillermo_Lopez | last post by:
Hello All, I am using VBA in access to perform some calculations. There is a particular sumation that is wrong (barely). this code is withing a loop. TDist = TDist + TempDist Both TDist...
11
by: fred.l.kleinschmidt | last post by:
If one knows that x and y are unsigned integers (of unknown size - they may be short, int, long, long long), what is the most portable way to determine their difference? If x is smaller than y,...
5
by: Joe | last post by:
I'm trying to add the current time + a randomly generated time w/ millisecond precision, but the numbers aren't making sense. If I add rand_time + now_time on my calculator, I get a different...
2
by: Canye | last post by:
I have a very long list of codes that i was advised to put in a module but don't know where to start from. Also i have a botton in my software that i what to use to be adding tabs when running my...
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
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...
1
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.