Guideline C: Respect for culture and conventions

C6: Numeric value

Allowing the selection of numeric value format
Numeric value formats are considered here separately from monetary amount formats, which may use different conventions.

Negative numbers
Negative number representation does not have a universal form. Some countries use a leading hyphen to denote negative non-monetary numbers, some place the hyphen after the number, and some use another symbol altogether.

Example: The following list shows several ways to portray the number negative ten:

Decimal and thousands separators
Different regions of the world use different characters for the decimal and thousands separators. The term decimal separator is a misnomer, because many countries do not use the dot symbol as the decimal separator. The more correct term is the radix character.

Example: The following list shows some of the ways to present numeric values:

Guideline C6


Allow the user to select the numeric value format.

Example: The following Java program uses the NumberFormat class to present a given number in a culturally correct format:

import java.text.*;
import java.util.*;
public class GuidelineC6 extends Gudieline {
private static final String RESOURCE = "GuidelineC6";
private double number = 1234567.891;
public String getItRight() {
ResourceBundle bundle = ResourceBundle.getBundle
(RESOURCE, Sample.locale);
NumberFormat nf =
NumberFormat.getInstance(Sample.locale);
/* replace Sample.locale with Locale.US
to explicitly specify the English Locale
or with Locale.GERMANY
to explicitly specify the German Local
*/
return nf.format(number);
}
public String getResource() {
return RESOURCE;
}
}

Depending on the user's preference, the following results would be achieved:


User's Preference Result
USA -1,234,567.891000
Germany -1.234.567,891000
France -1 234 567,891000