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(",", ""));  

相关文章:

  • 2021-11-10
  • 2021-12-31
  • 2021-11-27
  • 2021-07-29
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-12-10
  • 2021-11-20
  • 2021-08-08
  • 2021-07-21
  • 2021-11-19
  • 2022-12-23
  • 2022-01-16
相关资源
相似解决方案