How many decimal Places in A Double (Java)

前端 未结 7 998
南方客
南方客 2020-11-30 14:19

Is there any in built function in java to tell me how many decimal places in a double. For example:

101.13 = 2
101.130 = 3
1.100 = 3
1.1 = 1
-3.2322 = 4 etc         


        
7条回答
  •  温柔的废话
    2020-11-30 14:43

    The number of decimal places in a double is 16.

    64-bit numbers. 52-bit Mantissa. 52 bits is about 16 decimal digits.

    See http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html.

    double, whose values include the 64-bit IEEE 754 floating-point numbers.

    See http://en.wikipedia.org/wiki/IEEE_754-2008

提交回复
热议问题