vb 中text怎么才能只让它输入最多带两位小数的数

来源:百度知道 编辑:UC知道 时间:2024/05/19 19:41:47

在KeyPress事件中:

Dim i As integer
i = InStr(1, Text1.Text, \".\") \'返回小数点位置
If i = 0 then \'没有小数点(整数)
Else
if i >= Len(Text1.text)-2 \'-1是二位小数 或 一位小数+小数点 -2是两位小数+小数点
Else
Mid(Text1.text,0,i+2) \'截去多余小数点
end if
end if