以前我格式化字符串时喜欢用String.format,如:
String str = String.format("hello:%s", 1001);
System.out.println(str);
输出结果即是我要的期望值:hello:1001
然而,我有一天想换个用法时,也就是MessageFormat.format():
String str = MessageFormat.format("hello:{0}", 1001);
System.out.println(str);
结果得到了一个期望外的值:hello:1,001
为了避免默认的数字类型格式,format时我只能转成String了:
String str = MessageFormat.format("hello:{0}", String.valueOf(1001));
System.out.println(str);