[英]What does $%,.2f represent?
I am currently reading the Deitel's book on Java, and came across this code in one of their programs: 我目前正在阅读Deitel关于Java的书,并在其中一个程序中遇到了这段代码:
public String toString()
{
return String.format( "%s: %s\n%s: $%,.2f; %s: %.2f",
"commission employee", super.toString(),
"gross sales", getGrossSales(),
"commission rate", getCommissionRate() );
}
As the title says, what does the "$%," in front of the ".2f" represent? 正如标题所说,“。2f”前面的“$%”代表什么? I already know what a .2f means.
我已经知道.2f意味着什么。
$是字面上的美元符号,而%是参数%,。2f(带有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). %
字符在这里采用它的通常含义 - 用值替换(这里,带有2个小数位)。
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. 有关详细信息,请参阅
Formatter
javadocs的“参数索引”部分。
%,.2f
- 使用逗号格式化带有2个小数位的浮点数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.