使用NumberFormatInfo类的CurrencyDecimalSeparator属性来完成的。运行程序,效果如图1和图2所示。

           

图1  自定义$符                 图2  自定义*符

CurrencyDecimalSeparator属性获取或设置要在货币值中用做小数点分隔符的字符串。其语法格式如下:

public string CurrencyDecimalSeparator { get; set; }

属性值:要在货币值中用做小数点分隔符的字符串,默认值为“.”。

主要代码如下:

 System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN"false).NumberFormat;
        Int64 myInt 
= 123456789;
        
private void button1_Click(object sender, EventArgs e)        
        
{
            GN.CurrencyDecimalSeparator 
= "$";
            MessageBox.Show(
"定义前:" + myInt.ToString("C"+ "\n" + "定义后:" + myInt.ToString("C", GN), "自定义小数点为$符");
        }


        
private void button2_Click(object sender, EventArgs e)
        
{
            GN.CurrencyDecimalSeparator 
= "*";
            MessageBox.Show(
"定义前:" + myInt.ToString("C"+ "\n" + "定义后:" + myInt.ToString("C", GN), "自定义小数点为*符");
        }
posted on 2007-12-30 00:56  Travelling  阅读(306)  评论(0编辑  收藏  举报