使用Format和Printf进行混淆解码

时间:2013-07-22 19:54:42

标签: java

我是使用format()和printf方法进行字符串格式化的新手。我已经阅读了Oracle网站上的教程,但发现它非常令人困惑。所以决定尝试一些例子。我得到了这个样本 已将输出理解为124.00

public class TestStringFormatter {
  public static void main(String[] args){
    /* I do understand % - denotes start of instruction
       , is the flag
       6 - denotes width
       2 - Denotes precision
       f - Type */  
    String s = String.format("%,6.2f",124.000) ;
    System.out.printf(s);
  }
}

我无法理解的是,旗帜是如何在这种格式中使用的? 有人可以解释在这个例子中使用标志“,”。

1 个答案:

答案 0 :(得分:1)

逗号标记表示将使用逗号分隔数千个,至少在美国。在其他国家,它将使用在这些国家更有意义的分隔符。例如,使用逗号标记格式化123将产生123,使用逗号标记格式化123456789将产生123,456,789