"Klixx0r" <(E-Mail Removed)> wrote in message

news:su2vd.880$(E-Mail Removed)...

> I have a problem when adding 2 floats together.

>

> I add 1.235 and 0.001 together and get 1.2360001. Substraction

> works fine.

>

> With the addition I need the answer 1.236 and just that. Is there

> any solution to this problem?
The problem is actually that you don't understand how floating point numbers

work. Many simple decimal numbers (e.g. 0.001) repeat indefinately when

represented in binary and cannot be represented precisely. If precision is

critical for you, as it would be for financial data, try BigDecimal.

Otherwise, accept that real numbers cannot be represented with perfect

precision in a finite number of bits and round the number to the something

acceptable and format the result to ignore the result. Look at Math.round /

floor / ceil and DecimalFormat.

Cheers,

Matt Humphrey

http://www.velocityreviews.com/forums/(E-Mail Removed) http://www.iviz.com/