自定义字符串格式:ToString(“00”)
给出以下代码:
string istanbul = "523";
Convert.ToInt32(istanbul.ToString("00"));
它返回什么?
Given the following code:
string istanbul = "523";
Convert.ToInt32(istanbul.ToString("00"));
what does it return?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“0”自定义格式说明符用作零占位符符号。如果正在格式化的值在格式字符串中出现零的位置有一个数字,则该数字将被复制到结果字符串中;否则,结果字符串中会出现零。小数点前最左边的零和小数点后最右边的零的位置决定了结果字符串中始终存在的数字范围。
“00”说明符使值四舍五入到小数点前最接近的数字,其中始终使用远离零的四舍五入。例如,使用“00”格式化 34.5 将得到值 35。
“0”自定义说明符
链接文本
The "0" custom format specifier serves as a zero-placeholder symbol. If the value that is being formatted has a digit in the position where the zero appears in the format string, that digit is copied to the result string; otherwise, a zero appears in the result string. The position of the leftmost zero before the decimal point and the rightmost zero after the decimal point determines the range of digits that are always present in the result string.
The "00" specifier causes the value to be rounded to the nearest digit preceding the decimal, where rounding away from zero is always used. For example, formatting 34.5 with "00" would result in the value 35.
The "0" Custom Specifier
link text
这甚至无法编译:
您不能将数字分配给这样的字符串变量。您也没有使用
;
正确终止该语句。C# 也区分大小写,因此
istanbul
和Istanbul
引用不同的变量。要回答这个问题:
请阅读自定义数字格式字符串。
This will not even compile:
You cannot assign a number to a string variable like that. You also did not terminate the statement properly with a
;
.C# is also case sensitive, so
istanbul
andIstanbul
refer to different variables.To answer the question:
Read about custom numeric formatting strings.