效果图:
代码:
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("输入数字不合法!", "提示");
}
}
}
}