1、定义textbox的数据
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Text = String.Format("{0:C2}", 0.00);
}
private void textBox1_Leave(object sender, EventArgs e)
{
string aaa = String.Format("{0:C2}", Convert.ToDecimal(this.textBox1.Text.Replace("¥", "")));
this.textBox1.Text = aaa;
}
不过负数显示为: -¥123.79
2、定义datagridview的单元格的显示格式为货币类型:
this.dataGridView1.Columns["oil_add1"].DefaultCellStyle.Format = "C2";
3、将货币类型转化为数值类型以便提交到数据库中:
this.textBox1.Text = Convert.ToString(this.textBox1.Text.Replace("¥", "").Replace(",", ""));