- private void tbPrices_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != 46 && e.KeyChar != 8 && (e.KeyChar < 48 || e.KeyChar > 57))
- {
- e.Handled = true;
- }
- }
其中e.keychar !=46代表只能输入小数点
e.keychar!=8代表输入向前的删除键
(e.keychar<48||e.keychar>57)代表输入0-9的数字
string strproint=this.tbPrices.Text.Trim();
//获得小数点个数
int intPrize = strproint.Length - strproint.Replace(".", "").Length;
//字符串第一位数是什么。
string strPrize1 = strproint.Substring(0, 1);