C开发经验技巧宝典(11)
发布时间:2021-06-07
发布时间:2021-06-07
strInt+= "\n{ 2, 3,
2 }格式:" + myInt.ToString("p",GN);
int[] MySizes3 = { 1, 2, 3 }; GN.PercentGroupSizes=MySizes3;
strInt+= "\n{ 1, 2, 3 }格式:" + myInt.ToString("p",GN);
MessageBox.Show(strInt, "设置效果", MessageBoxButtons.OK, rmation); }
本实例主要介绍如何使用NumberFormatInfo类的PercentSymbols属性设置百分比符号。运行程序,效果如图5.10所示。
PercentSymbols属性用于获取或设置用作百分比符号的字符串。其语法格式如下:
public string PercentSymbol { get; set; }
属性值:用作百分比符号的字符串,默认值为“%”。 主要代码如下:
private void button1_Click(object sender, EventArgs e) {
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN",false).NumberFormat;
double intPrecnt = 102578.6584; string strPrecnt = null; GN.PercentSymbol = "%";
strPrecnt += "默认符号: " + intPrecnt.ToString("p",GN); GN.PercentSymbol = "&";
strPrecnt += "\n自定义符号&: " + intPrecnt.ToString("p", GN); GN.PercentSymbol = "*";
strPrecnt += "\n自定义符号*: " + intPrecnt.ToString("p", GN); GN.PercentSymbol = "#";