Number Format example


import java.text.*;


public class FormatTest {

  public static void main(String[] args) {

    NumberFormat nf = NumberFormat.getInstance();
    for (double x = Math.PI; x < 100000; x *= 10) {
      String formattedNumber = nf.format(x);
      System.out.println(formattedNumber + "\t" + x);
    }

  }

}

U.S. English system results:
3.141        3.14159265358979
31.415      31.4159265358979
314.159     314.159265358979
3,141.592       3141.5926535897897
31,415.926  31415.926535897896

French results:
3,141        3.14159265358979
31,415      31.4159265358979
314,159     314.159265358979
3 141,592       3141.5926535897897
31 415,926  31415.926535897896

Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified January 29, 2000