c# - 如何检查 TextBox.Text 是否为整数?
问题描述
我需要检查我的 TextBox 是否包含整数,即使是这种格式:“5.00”
我尝试了 Integer.TryParse(),但它返回 False。它仅在这种情况下起作用,当 TextBox 包含以下格式的数字时:“5”
解决方案
将您的字符串编号转换为Double
然后使用Math.Round()
方法检查
//Convert to Double && round double number and check with original double number
if((Double.TryParse(textValue, out double number)) && Math.Round(number) == number)
{
//Here you go;
}
推荐阅读
- php - 如何识别 Wordpress 默认文本小部件的单个实例?
- reactjs - 使用 react-router 时如何防止 React 应用程序崩溃
- laravel - 将 Laravel 从 5.4 升级到 5.7 后出现 Artisan 错误
- javascript - 如何将来自控制器的 JSON 响应存储在 Javascript 变量中
- opencv3.0 - 自适应阈值和轮廓检测
- ruby-on-rails - 我无法使用 SFTP(Filezilla 软件)通过下载文件并在本地机器文本编辑器上编辑来更新 ruby on rails 生产代码
- ios - 如何为 Mobile SDK iOS 生成许可证密钥
- sql - 看不到任何添加到我的表中的东西,如果它被添加的话
- r-exams - `exams2nops()` 中的多个图
- airflow - 气流:既没有设置 SQLALCHEMY_DATABASE_URI 也没有设置 SQLALCHEMY_BINDS