How to add two double values?

Hi.

I am facing this problem.

double d1=5421.725

double d2=10503.45

when i add d1+d2 in java , the value is 15925.175000000001.

But my doubt is how the last decimal value '1' comes in the value.

The answer should be 15925.175.

Please help me out to solve this problem.

Bye

Mullai

[342 byte] By [mullaimarana] at [2007-11-27 11:18:15]
# 1

That's how floating point numbers work. Read this:

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

And learn how to use java.text.NumberFormat.

%

duffymoa at 2007-7-29 14:29:47 > top of Java-index,Java Essentials,Java Programming...
# 2

http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2

http://mindprod.com/jgloss/floatingpoint.html

jverda at 2007-7-29 14:29:47 > top of Java-index,Java Essentials,Java Programming...