如何将文本框的输入转换为十进制数 [英] How to convert input from a TextBox into a decimal number

查看:55
本文介绍了如何将文本框的输入转换为十进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要创建的:一个程序,用户可以在其中输入任何十进制数并被告知该数字的所有性质.(例如:偶数/奇数、可被 2/5/10 整除、是质数等...)

Here is what I want to create: A program where the user can enter any decimal number and is told all the qualities of that number. (For example: even/odd, divisible by 2/5/10, is a prime number, etc...)

遗憾的是,我已经无法从用户输入中获取数字.

Sadly I'm already failing at grabbing the number from the user input.

  1. 我需要一个只允许数字的文本框.(我知道 NumericUpDown 是一个选项,但我想用 TextBox 尝试一下)

  1. I need a TextBox that only allows Numbers. (I know NumericUpDown is an option but I wanted to try it with a TextBox)

我需要将 TextBox 中的字符串转换为 float(?)(或 double?).我知道 int 不起作用,因为我不希望它削减所有小数位.

I need to convert the String from the TextBox into a float(?) (or double?). I know int won't work because I don't want it to cut all the decimal places.

我需要测试所有质量的数字,然后报告.(我会处理的).

I need to test the number for all the qualities and then report back. (I´ll manage that).

我需要有关步骤 1 和的帮助2.

I need help with steps 1 & 2.

推荐答案

你在用什么?WPF、Windows 窗体还是 ASP.NET?至于将其转换为十进制,您所要做的就是解析它或使用 Convert 类.很可能您只需将文本框的名称称为文本访问器,然后将其作为参数传递给转换或解析,然后将其填充到变量中.

What are you using? WPF, Windows Forms or ASP.NET? As for converting it to a decimal all you have to do is parse it or use the Convert class. Most likely you'll just put the name of your text box call it's text accessor and pass it in to a convert or parse as a parameter and stuff it into a variable.

这篇关于如何将文本框的输入转换为十进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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