0

I'd like to format float numbers in a pretty manner like so:

1432.432342003 to 1.432,43

I can format it from 1432.432342003 to 1432,43 loike so:

 DecimalFormat decimalFormat = new DecimalFormat("#.##");
 String pretyStr = decimalFormat.format(input);

so how to achieve this, maybe there is a easy way like #.###.## - I don't want to take int part aside and float part aside

ankuranurag2
  • 2,300
  • 15
  • 30
Choletski
  • 7,074
  • 6
  • 43
  • 64
  • Did you check [this other answer](https://stackoverflow.com/questions/36418901/change-decimalformat-locale)? – m0skit0 Jan 30 '19 at 10:52
  • Look at [this](https://stackoverflow.com/questions/5323502/how-to-set-thousands-separator-in-java) also – Massimo Jan 30 '19 at 10:53
  • 3
    Possible duplicate of [Change DecimalFormat locale](https://stackoverflow.com/questions/36418901/change-decimalformat-locale) – asyard Jan 30 '19 at 10:58

4 Answers4

0

try this:

 DecimalFormat decimalFormat = new DecimalFormat("#,###.##");
 String pretyStr = decimalFormat.format(input);
Gianluca Pinto
  • 235
  • 3
  • 6
0

What you want is called a thousands separator, in english-speaking countries the usual format is 12,345,678.90

You may use the following format with DecimalFormat: ###,###.### The result of 123456.789 with this format shoudl be 123,456.789

You can find more information on DecimalFormat here

EDIT1: Example

 DecimalFormat decimalFormat = new DecimalFormat("###,###.##");
0

The format you're looking for is

DecimalFormat decimalFormat = new DecimalFormat("#,###.##");

But be careful, separators may change with your locale, and you may need to use a NumberFormat to control that

Marco
  • 127
  • 6
0

I got it like so:

  public static String getPrettyPrintVal(double input){
    final DecimalFormat decimalFormat = new DecimalFormat("###,###.###", DecimalFormatSymbols.getInstance(Locale.GERMANY));
    return decimalFormat.format(input);
}

3214234.234 ==> 3.214.234,234

Choletski
  • 7,074
  • 6
  • 43
  • 64