Floating point numbers : Message Format « I18N « Java Tutorial






import java.text.MessageFormat;

public class Main {
  public static void main(String[] argv) throws Exception {

    Object[] params = new Object[] { new Double(123.45), new Double(1234.56) };
    String msg = MessageFormat.format("{0,number,#.#} a''s and {1,number,#.#} b''s", params);
    System.out.println(msg);
  }
}








13.12.Message Format
13.12.1.Use MessageFormat to format a sentence
13.12.2.Date Number Sample
13.12.3.Substitute tokens in a String
13.12.4.Formatting a Message Containing a Number
13.12.5.Format message with Integer fillers
13.12.6.Use a custom format
13.12.7.Floating point numbers
13.12.8.Currency number format
13.12.9.Percent value format
13.12.10.Formatting a Message Containing a Time
13.12.11.Format Date() in short format
13.12.12.Format Date() value in medium format
13.12.13.Format Date() in long
13.12.14.Format Date value in full length
13.12.15.Use a custom format for Date value
13.12.16.Formatting a Message Containing a Date
13.12.17.Combine date value in a sentence
13.12.18.Set MessageFormat to Locale.US