I am doing a few math calculations, and my return type is a double, but it keeps coming back as ##.0
I have tried to use String.format("%.2f", myDouble) but its still only returning a single 0. Any ideas?
Printable View
I am doing a few math calculations, and my return type is a double, but it keeps coming back as ##.0
I have tried to use String.format("%.2f", myDouble) but its still only returning a single 0. Any ideas?
Can you show us your code?
You can use DecimalFormat class for this.
e.g.-->
Output:Code:double d = 123.984212;
DecimalFormat format = new DecimalFormat();
format.setMaximumFractionDigits(4);
System.out.println(format.format(d));
123.9842