效果图:

代码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Globalization;

namespace Example51

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            double P_dbl_value;

            if (double.TryParse(textBox1.Text, out P_dbl_value))

            {

                NumberFormatInfo NFI = new CultureInfo("zh-CN", false).NumberFormat; //实例化NumberFormatInfo对象

                NFI.CurrencyGroupSeparator = ",";           //设置货币值中用来分组的字符串

                textBox2.Text = P_dbl_value.ToString("C", NFI);  //格式化为货币格式 并输出

            }

            else

            {

                MessageBox.Show("输入数字不合法!", "提示");

            }

        }

    }

}

posted on 2011-10-23 17:33  C#_初学者  阅读(339)  评论(0编辑  收藏  举报