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

Answer:

Default Locale = fr_FR
value = 12 345,6789

Specifying the Locale

import java.util.Locale;

public class LocaleDemoTwo
{
  public static void main ( String[] args )
  {
    double value = 12345.6789 ;

    System.out.printf( Locale.ITALY, "value = %,10.4f%n", value );  
  }
}

You can specify the Locale to use. The above program asks to format the value using Locale.ITALY It outputs:

value = 12.345,6789

Different countries use different formats for numbers. Usually you don't need to worry about this. Your environment will usually be set up to use the right locale for your location

Another form of printf() looks like this:

printf(locale, formatString, value1, value2, value3, ...)

Here are some locales you might want to play with.


QUESTION 9:

Do you suspect that the following works?

    Integer myInt = 12345 ;
    System.out.printf("myInt = %,6d%n", myInt );

    Float myFloat =  12345.54f  ;
    System.out.printf("myFloat = %,10.2f%n", myFloat );

Reminder: The 12345.54f is a single precision float literal. Without the "f" it would be double.




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