GN.PercentGroupSeparator =
"、";
strSperar += "\n用顿号作分隔符:" + myInt.ToString("P", GN); GN.PercentGroupSeparator = "'";
strSperar += "\n用单引号作分隔符:" + myInt.ToString("P", GN); MessageBox.Show(strSperar, "定义效果"); }
本实例主要介绍如何使用NumberFormatInfo类的PercentGroupSizes属性设置百分比小数点左边每一组的位数。运行程序,效果如图5.9所示。
PercentGroupSizes属性获取或设置百分比值中小数点左边的每一组的位数。其语法格式如下:
public int[] PercentGroupSizes { get; set; }
属性值:百分比值中小数点左边的每一组的位数。默认值是一个一维数组,该数组只包含一个设置为3的元素。
主要代码如下:
private void button1_Click(object sender, EventArgs e) {
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;
Double myInt= 510214720805231.4835; string strInt =null;
strInt+= "默认格式:" + myInt.ToString("p",GN); int[] MySizes1 = { 2, 3, 4 }; GN.PercentGroupSizes=MySizes1;
strInt+= "\n{ 2, 3, 4 }格式:" + myInt.ToString("p",GN); int[] MySizes2 = { 2, 3, 2 }; GN.PercentGroupSizes=MySizes2;