Well, as you know, doubles and floats are a specific number of bits wide. That means you can only cram so much information into them. 4.2 * 12.09 is no problem. But how about 34998729873948792879387948793879234.019872987349871234908798734928734928734987 * 0.00000000000000000000000000000023498729384729834792834792837492837492834729843273928?

If you add, subtract, multiply, divide *money* BigDecimal will give you the answers you expect. Floats and Doubles will be full of unpleasant surprises.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi

Originally posted by Marco Vanoli: ...con you quickly explain why, when use them? ...

Basically, if you're okay with small errors due to lack of precision -- like 0.30000000000000004 instead of 0.3 -- then doubles are fine. But whenever you need precise results, then use BigDecimal.

Originally posted by Marco Vanoli: ...there is maybe a tutorial that explain use of Bigint?

BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

System.out.println("Here's a bigger number: " + bInt);

System.out.println("Here it is as a double: " + bInt.doubleValue( )); }

}

import java.math.*;

Here's Long.MAX_VALUE: 9223372036854775807 Here's a bigger number: 3419229223372036854775807 Here it is as a double: 3.419229223372037E24 Press any key to continue...

tnks for reply marc [ July 23, 2005: Message edited by: Marco Vanoli ]

Originally posted by Marco Vanoli: ...Here's Long.MAX_VALUE: 9223372036854775807 Here's a bigger number: 3419229223372036854775807 Here it is as a double: 3.419229223372037E24...

Yeah, I recall using BigInteger for handling very large numbers when I was writing the "ultimate" factoring program. (Doesn't everyone write one of these?) My program used BigInteger until the remainder was "small" enough to use primitives, when it switched over to long. I never actually verified whether this switch was more efficient.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.