自定义字符串格式:ToString("00") [英] Custom string formatting: ToString("00")

查看:115
本文介绍了自定义字符串格式:ToString("00")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下代码:

string istanbul = "523";
Convert.ToInt32(istanbul.ToString("00"));

它返回什么?

推荐答案

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.

00"说明符使值四舍五入到小数点前最接近的数字,其中始终使用远离零的四舍五入.例如,使用00"格式化 34.5 将导致值 35.

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.

0"自定义说明符链接文本

这篇关于自定义字符串格式:ToString("00")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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