$%,. 2f代表什么? [英] What does $%,.2f represent?

查看:124
本文介绍了$%,. 2f代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在阅读Deitel的有关Java的书,并在他们的一个程序中发现了以下代码:

I am currently reading the Deitel's book on Java, and came across this code in one of their programs:

public String toString()
{
  return String.format( "%s: %s\n%s: $%,.2f; %s: %.2f", 
     "commission employee", super.toString(), 
     "gross sales", getGrossSales(), 
     "commission rate", getCommissionRate() );
}

正如标题所述,.2f"前面的"$%"代表什么?我已经知道.2f是什么意思.

As the title says, what does the "$%," in front of the ".2f" represent? I already know what a .2f means.

推荐答案

$ 字符在这里没有什么特别的意思.它只是显示在字符串中的文字 $ .字符在这里具有通常的含义-用一个值替换(这里用2个小数位).

The $ character means nothing special here. It's just a literal $ to show up in the string. The % character takes it's usual meaning here -- to substitute with a value (here, with 2 decimal places).

请注意, $ 字符可能在字符后具有含义.请参见 的参数索引"部分.格式化程序 javadocs了解详情.

Note that it's possible for the $ character to have meaning after the % character. Please see the "Argument Index" section of the Formatter javadocs for details.

这篇关于$%,. 2f代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆