Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

try this

    NumberFormat f = NumberFormat.getNumberInstance(Locale.US);
    f.setMinimumFractionDigits(2);
    String s = f.format(53508);

Try this in Kotlin :

val n = NumberFormat.getNumberInstance(Locale.US)
n.maximumFractionDigits = 2
n.minimumFractionDigits = 2

And after format your number with :

n.format(53508)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top