格式字符串到3位数 [英] Format string to a 3 digit number
本文介绍了格式字符串到3位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
而不是这样做的,我想利用的String.Format()
来完成同样的结果:
如果(myString.Length 3;)
{
的myString =00+ 3;
}
解决方案
如果你只是格式化一个数字,你可以提供适当的自定义数字格式直接使之成为3的数字串
的myString = 3.ToString(000」);
或者也可使用的标准的D格式字符串:
的myString = 3.ToString( D3);
Instead of doing this, I wanted to make use of string.format()
to accomplish the same result:
if (myString.Length < 3)
{
myString = "00" + 3;
}
解决方案
If you're just formatting a number, you can just provide the proper custom numeric format to make it a 3 digit string directly:
myString = 3.ToString("000");
Or, alternatively, use the standard D format string:
myString = 3.ToString("D3");
这篇关于格式字符串到3位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文