Formatting values in the house of millions

3

I want to format values in the millions. Example:

The result of a calculation would be 1.960,35 . But the output is 19603565.2315789 .

I was using DecimalFormat , but it was for smaller numbers. How to do this in the house of millions?

    
asked by anonymous 26.03.2016 / 02:15

1 answer

3

You can use the NumberFormat class to format. Example:

    double num = 12345678.90;
    Locale ptBr = new Locale("pt", "BR"); //define a região
    NumberFormat moeda = NumberFormat.getCurrencyInstance(ptBr);
    System.out.print(moeda.format(num)); 

Or all in one line:

System.out.print(NumberFormat.getCurrencyInstance(ptBr).format(num));
    
26.03.2016 / 16:23