Formatting

The following can require formatting:

  • Texts

  • Dates

  • Numbers

  • Currencies

Texts

Compound Messages

Having this message bundle:

template = The employee {0} has the id {1,number,integer}
ResourceBundle messages;
Object[] messageArguments;
MessageFormat formatter;
String formatted;

messages = ResourceBundle.getBundle("MessageBundle", currentLocale);

messageArguments = {
   "John",
   new Integer(12)
};

formatter = new MessageFormat("");
formatter.applyPattern(messages.getString("template"));

formatted = formatter.format(messageArguments);

Plurals

Having this message bundle:

Which will print "There are 3 employees"

Dates

Numbers

For percentages:

Currencies

Patterns

Date Patterns

Numeric Patterns

More Information

Last updated

Was this helpful?