文本框中的数字格式 [英] number format in textbox

查看:172
本文介绍了文本框中的数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些要求,例如:
默认值应在文本框中显示为0.00.
并且这里有一些标准,例如小数点之前,它应该接受< = 13位数字,小数点之后,它应该只接受2位数字和.".应该是只读的.用户不应删除.".
如果用户输入类似"1234567890123.12"的值,那么我要显示格式"1,234,567,890,123.12".
例如:12345.56
输出:12,345.56

we have some requirement like:
Default values should be displayed as 0.00 in the textbox.
And here some criteria like before decimal, it should accept <=13 digits and after decimal it should accept only 2 digits and "." should be readonly.User should not able to remove "."
If user enter the value like "1234567890123.12" then i want to display the format "1,234,567,890,123.12".
Ex:12345.56
output:12,345.56

推荐答案

看看 ^ ]它应该可以执行您想要的操作,但是您可能需要在面具上摆弄一些...
Have a look at Masked Text Box[^] it should do what you want, but you may have to fiddle with the mask a bit...


就像汤姆已经建议的那样自定义控件可能是满足您要求的最有效方法.

为了帮助您进行设计,您应该研究String.Format() FormatStrings .
As Tom has already suggested a Custom Control would probably be the most efficient way to meet your requirements.

To help you in the design you should research String.Format() and FormatStrings.


您可以设置MaskEdit Control来满足您的要求,输入值后就可以使用format功能与您的期望输出一起显示.

如果要让文本框接受13或< 13字符,则必须使用format函数来满足您的要求.

用户文本框验证的事件并进行检查.

Txt_validated()
如果txt.text.length< 13然后
txt.text = format(txt.text,"#############.##")
如果
结束 结束子


要获取详细信息,只允许使用一个小数点,之后只能使用2位数字,这是因为您必须使用按键事件,并且使用instr函数可以检查是否存在小数点.
You can set MaskEdit Control to meet your requirement and after entering value you can use format function to display with your desire output.

If you want to your textbox should accept either 13 or <13 character then you must use format function to satisfy your requirement.

User textbox validated event and check it.

Txt_validated()
if txt.text.length < 13 then
txt.text = format(txt.text,"#############.##")
end if
end sub


For getting details that only one decimal point should allowed and after that only 2 digits can be allowed for that you have to use key press event and with instr function you can check whether decimal point is there or not.


这篇关于文本框中的数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆