Hi,
I am getting the double value like below
123456789123456789123456789123456789.22446688
I need to find the length of this double value.
I have tried the following ways:
1) Pretty ordinary way, just converted the incoming value to
String and find the length- It is giving wrong length.
2) Used NumerberFormat class like below:
double value=123456789123456123564789121.12345;
DecimalFormat format=new DecimalFormat(".");
String s =format.format(value);
s.length� will give us the length of the double including DOT except length of the digits after the decimal point.
3) If am replacing the line DecimalFormat format=new DecimalFormat ("#"); then,
s.length� will give us the length of the double excluding DOT except length of the digits after the decimal point.
4) We can able to get the length of the double value before decimal point with option 2 and 3. But, we are not able to find the length of the digits after decimal point. I tried with substring, it is also got failed.
5) Then, I have tried using the custom NumberFormat instance, it is giving the length of the double with minor deviation, we can understands that this minor difference due to custom NumberFormatting, I am not sure which format will give us the correct length of the double.
Also used BigDecimal,Please let us if anyone know the solution for this
Thanks in advance