我不太理解下面这行代码的格式是如何生成的。
谁能告诉我,它是如何将值以适当的逗号呈现在格式中,放在图中的正确位置。
writer.Write(string.Format("Your Estimated Loan Paymement+will be {0:$#,##0.00;($#,##0.00);Zero}", + this.calcPayment(this._pv,1,2) ));这里的calcPayment()是一个返回数值的函数。例如,如果返回2000.33,则输出为$2,003.33。
我知道它正在形成,但它是如何形成的?
谢谢。
发布于 2011-09-16 06:27:50
分解格式字符串:{0:$#,##0.00;($#,##0.00);Zero}
有3个组:
$#,##0.00 -当参数(本例中为positive.($#,##0.00) )为零时使用-当arg为negativeZero时使用-当arg为this.calcPayment(this._pv,1,2)时使用
#是数字占位符,0是零占位符(填充)。
有关详细信息,请参阅this。
发布于 2011-09-16 06:21:35
格式字符串中的逗号(例如$#,##0.00 )告诉它是否在需要时使用逗号(或者,正如@svick正确地指出的那样,“组分隔符”)。
实际情况是,Format方法(函数)使用格式字符串作为模板,然后添加您提供的附加数据。
发布于 2011-09-16 06:26:25
我大胆地猜测是这样的:
0: //this is telling it that this is the zero placeholder in the format string
$#,##0.00 //this is what happens if the value is above zero
($#,##0.00) //this is for values below zero
Zero //literal "Zero" output if the value is equal to zero编辑-从@Jon的评论中的链接中读取关于custom numeric format strings的信息,确认三个分号分隔的部分确实指定了正值、负值和零值的格式。
https://stackoverflow.com/questions/7438090
复制相似问题