Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double value with two decimal using NumberFormat

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).

like image 409
Anupam Sharma Avatar asked Apr 05 '14 06:04

Anupam Sharma


People also ask

How do you make a double show with two decimal places?

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 the number 2.738 correct to 2 decimal places?

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.


1 Answers

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
like image 122
Anupam Sharma Avatar answered Sep 19 '22 11:09

Anupam Sharma