0

Is there a simple way to format variables on a GUI with spaces (or commas) between so its easier to read.

Example:

int x = 12000000;

JLabel.setText(x); 

which outputs 1200000, however I am trying to achieve on of the following.

  • 1 200 000
  • 1,200,000
Nico
  • 12,493
  • 5
  • 42
  • 62
Shadowkillsa
  • 77
  • 1
  • 8
  • And also [Format currency without currency symbol](http://stackoverflow.com/questions/8658205/format-currency-without-currency-symbol) – Baby Jan 21 '14 at 06:24

2 Answers2

1

If you want to use the user's locale to determine whether to use commas or decimal points, use the following:

String formattedNum = NumberFormat.getIntegerInstance().format(x);

For Americans, you would see 1,200,000.

Kevin Ji
  • 10,479
  • 4
  • 40
  • 63
0

You can try this:

int x = 12000000;
JLabel.setText(NumberFormat.getInstance().format(x));
David Fleeman
  • 2,588
  • 14
  • 17