如何检查小数位后的数字。 [英] how to check the numbers after decimal place.

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

问题描述

我有文本框,只接受带小数位的数字。但我必须找到用户是否在小数点后输入了2位以上,如何找到小数点后的长度。

解决方案

既然你确定你的文字框中只包含数字,那么您可以简单地使用 String.Split [ ^ ]方法。例如。 (错误检查留给读者)



  string  [] a = textBox1.Text.Split( new   char  [] { ' 。'}); 
int decimals = a [ 1 ]。长度;


使用规则表达式验证文本框中的条目:



 ^ [0-9] + ([。] [0-9] {2})?






检查这个出去学习在c中使用正则表达式#



http:// www。 dotnetperls.com/regex-match [ ^ ]


i have the text box, that accepts only numbers with decimal place. But i have to find if the user has entered the more than 2 digits after decimal point, how find the length after decimal place.

解决方案

Since you are sure your text box contains just numbers then you might simply use the String.Split[^] method. E.g. (error checking left to the reader)

string[] a = textBox1.Text.Split(new char[] { '.' });
int decimals = a[1].Length;


Use regulation expression to validate the entry in the textbox:

^[0-9]+([.][0-9]{2})?




Check this out to learn to use regex in c#

http://www.dotnetperls.com/regex-match[^]


这篇关于如何检查小数位后的数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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