Hi all,
I have a Double with this value 136546.215454 and I want to convert it to: 136546.21 How can I do that (Only 2 decimals after ".")
Regards,
Sakthivel
Printable View
Hi all,
I have a Double with this value 136546.215454 and I want to convert it to: 136546.21 How can I do that (Only 2 decimals after ".")
Regards,
Sakthivel
There is a NumberFormat somewhere, I can help you find it.
google: "java NumberFormat"
Is it the display of the Double you want to change(ie when you print it) or the value of the Double? That is you want the value of the Double to be:136546.21000000 ie all zeros after the .21
A way might be to multiple the value by 100, convert to long and then convert to Double and divide by 100. For example:Code:double d = 1234.21345666;
d = d * 100.0;
long dI = (long)d;
double e = ((double) dI)/ 100.0;
System.out.println("d=" + d + ", e=" + e); //d=123421.34566600001, e=1234.21