title: What is the difference between {0} and {0,number,integer}
body: <p>I'm trying to understand more about Java's <a href="http://docs.oracle.com/javase/6/docs/api/java/text/MessageFormat.html" rel="nofollow">MessageFormat</a> utilities, and in examples in our codebase and elsewhere I see both <code>{0}</code> and <code>{0,number,integer}</code> being used for numbers, but I'm not sure which, if either, is preferable.</p>
  
  <p>A quick test printing the differences:</p>
  
  <pre><code>import java.text.MessageFormat;
  import java.text.NumberFormat;
  import java.util.Locale;
  
  public class MessageFormatTest
  {
      public static void main(String[] args){
          MessageFormat simpleChoiceTest = new MessageFormat("{0}");
          MessageFormat explicitChoiceTest = new MessageFormat("{0,number,integer}");
          int[] set = new int[]{0,1,4,5,6,10,10000,24345};
          Locale[] locs = new Locale[]{Locale.US,Locale.UK,Locale.FRANCE,Locale.GERMANY};
          for(Locale loc : locs){
              simpleChoiceTest.setLocale(loc);
              explicitChoiceTest.setLocale(loc);
              for(int i : set){
                  String simple = simpleChoiceTest.format(new Object[]{i});
                  String explicit = explicitChoiceTest.format(new Object[]{i});
                  if(!simple.equals(explicit)){
                      System.out.println(loc+" - "+i+":\t"+simple+
                          "\t"+NumberFormat.getInstance(loc).format(i));
                      System.out.println(loc+" - "+i+":\t"+explicit+
                          "\t"+NumberFormat.getIntegerInstance(loc).format(i));
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>fr_FR - 10000:  10 000  10 000
  fr_FR - 10000:  10,000  10 000
  fr_FR - 24345:  24 345  24 345
  fr_FR - 24345:  24,345  24 345
  de_DE - 10000:  10.000  10.000
  de_DE - 10000:  10,000  10.000
  de_DE - 24345:  24.345  24.345
  de_DE - 24345:  24,345  24.345
  </code></pre>
  
  <p>Which surprised me, if anything I would have expected the <code>{0}</code> to not do anything to the number, and for <code>{0,number,integer}</code> to localize it properly.  Instead, both get localized, but it seems the explicit form always uses en_US localization.</p>
  
  <p>According to the linked documentation, <code>{0}</code> gets put through <code>NumberFormat.getInstance(getLocale())</code> while while the explicit form uses <code>NumberFormat.getIntegerInstance(getLocale())</code>.  Yet when I call those directly (the last column in the output) both seem identical, and both localize correctly.</p>
  
  <p>What am I missing here?</p>