NumberFormat: setMinimumIntegerDigits(int newValue) : NumberFormat « java.text « Java by API






NumberFormat: setMinimumIntegerDigits(int newValue)

 
/*
0.0 formats as 000.00
1.0 formats as 001.00
3.142857142857143 formats as 003.1429
100.2345678 formats as 100.2346
 */
import java.text.NumberFormat;

public class MainClass {

  public static void main(String[] av) {
    double data[] = { 0, 1, 22d / 7, 100.2345678 };
    NumberFormat form = NumberFormat.getInstance();

    // Set it to look like 999.99[99]
    form.setMinimumIntegerDigits(3);
    form.setMinimumFractionDigits(2);
    form.setMaximumFractionDigits(4);

    // Now print using it.
    for (int i = 0; i < data.length; i++)
      System.out.println(data[i] + "\tformats as " + form.format(data[i]));
  }

}

           
         
  








Related examples in the same category

1.NumberFormat: format(Object obj)
2.NumberFormat.getCurrencyInstance();
3.NumberFormat: getCurrencyInstance(Locale.UK)
4.NumberFormat: getInstance()
5.NumberFormat: getNumberInstance()
6.NumberFormat: getNumberInstance(Locale.FRENCH)
7.NumberFormat: getIntegerInstance(Locale.ITALIAN)
8.NumberFormat: getNumberInstance(Locale inLocale)
9.NumberFormat: getPercentInstance(Locale inLocale)
10.NumberFormat: parse(String source)
11.NumberFormat.setMaximumFractionDigits(int newValue)
12.NumberFormat: setMinimumFractionDigits(int newValue)
13.NumberFormat: setParseIntegerOnly(boolean value)