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.
I am happy to convert to another type first if needed, I have looked at converting to bigdecimal first with no luck.
No.
1.100 and 1.1 are exactly the same value (they are represented exactly the same bit-for-bit in a
double).Therefore you can’t ever get that kind of information from a
double.The only thing you can do is to get the minimum number of decimal digits necessary for a decimal number to be parsed into the same
doublevalue. And that is as easy as callingDouble.toString()and checking how many decimal digits there are.