A double does not have a decimal point. It has a mantissa, which always has a single 1 before the radix point, and an exponent, and a sign. You can Google IEEE754 for more details. So "number of places beyond the decimal point" is meaningless. The only floating-point number which actually has a decimal point is BigDecimal. But don't try converting a double to a BigDecimal, otherwise you will get a display with dozens of digits after the decimal point. I believe there are methods in BigDecimal which give you the number of places directly.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44006

33

posted

0

I earlier wrote:. . . mantissa . . . always has a single 1 before the radix point, . . .

. . . except for values with an absolute value < this, or ±0, or ∞ or "NaN". The 1 in "normal" values is implicit; it isn't actually stored in memory.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com

subject: How to count the number of digits after decimal point in java?