★搜Asp.net★(www.soAsp.net),为专业技术文档网站。
包括Asp.net开发技术文档·C#开发技术文档·Access/SQL Server数据库开发技术文档·VB.NET开发技术文档。
还包括·项目实战经验总结·开发经验技巧总结·项目开发心得。


  
C#如何自定义百分比小数点

本技巧主要介绍如何使用NumberFormatInfo类的PercentDecimalSeparator属性设置百分比小数点分隔符的字符串。PercentDecimalSeparator属性

此属性取或设置在百分比值中用作小数点分隔符的字符串。

其语法格式为:

public string PercentDecimalSeparator { get; set; }

l  属性值:在百分比值中用作小数点分隔符的字符串。默认值为“.”

主要代码如下:

        private void button1_Click(object sender, EventArgs e)
        {
            System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;
            Double myInt = 0.122434;
            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, "定义效果");
        }