go to previous page   go to home page   go to next page

Answer:

That depends on where you are. Some possible choices are

123,456,789
123.456.789
123 456 789

In Canada, UK, and US, commas are used to separate groups of three digits. Other countries use periods or spaces for that purpose.

Default Locale

When the Java virtual machine starts running on a computer, it creates an object called the default locale. This object affects how some methods format data. Here is a program that writes different strings for the same number, depending on where it is run.

import java.util.Locale;
import java.text.*;

class IODemo
{
  public static void main ( String[] args )
  {
    int value = 123456789 ;
    
    System.out.println( "Default Locale = " + Locale.getDefault() );
    DecimalFormat decform = new DecimalFormat();   
    System.out.println( "value = " + decform.format(value) );
  }
}

On my computer (in the US) this program writes

Default Locale = en_US
value = 123,456,789

The number has been formatted correctly for the locale in which the program is running.

The static method Locale.getDefault() asks the virtual machine for a reference to its default locale object. The println() statement uses that object's toString() method to produce: en_US.

This specifies that the default language is English and the default country is US. Your computer might output a different locale code and may format the number differently.

QUESTION 2:

Would the program print something different if it were running in Great Britain?