string strPercent = null;
GN.PercentDecimalSeparator = "
";
strPercent += "用空格代替小数点:" + myInt.ToString("P", GN); GN.PercentDecimalSeparator = "@";
strPercent += "\n用@符代替小数点:" + myInt.ToString("P", GN); GN.PercentDecimalSeparator = "#";
strPercent += "\n用#符代替小数点:" + myInt.ToString("P", GN); GN.PercentDecimalSeparator = "*";
strPercent += "\n用*号代替小数点:" + myInt.ToString("P", GN); MessageBox.Show(strPercent, "定义效果"); }
本实例主要介绍如何使用NumberFormatInfo类的PercentGroupSeparator属性设置百分比小数点左边的分节号。运行程序,效果如图5.8所示。
PercentGroupSeparator属性获取或设置在百分比值中对小数点左边数字进行分组的字符串。其语法格式如下:
public string PercentGroupSeparator { get; set; }
属性值:在百分比值中对小数点左边数字进行分组的字符串,默认值为“,”。 主要代码如下:
private void button1_Click(object sender, EventArgs e) {
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;
Double myInt = 12345.678; string strSperar = null;
GN.PercentGroupSeparator = ",";
strSperar += "用逗号作分隔符:" + myInt.ToString("P", GN);