I am using java.text.NumberFormat
to convert my double value to two decimal with conman separate format.
My code of line is:
NumberFormat.getNumberInstance(Locale.US).format(53508));
This code will convert 53508 to 53,508 format but I require in 53,508.00 format (with 2 decimal).
Just use %. 2f as the format specifier. This will make the Java printf format a double to two decimal places. /* Code example to print a double to two decimal places with Java printf */ System.
What is 2.738 Round to Two Decimal Places? In the given number 2.738, the digit at the thousandths place is 8, so we will add 1 to the hundredths place digit. So, 3+1=4. Therefore, the value of 2.738 round to two decimal places is 2.74.
Thanks Friends I solve it .... :)
Below is line of code
NumberFormat formatter = NumberFormat.getInstance(Locale.US);
formatter.setMaximumFractionDigits(2);
formatter.setMinimumFractionDigits(2);
System.out.prinitln(formatter.format(53508));
and output is
53,508.00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With