Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASPX C#网站的文本框中接受双倍值?_C#_Double_Decimal - Fatal编程技术网

如何在ASPX C#网站的文本框中接受双倍值?

如何在ASPX C#网站的文本框中接受双倍值?,c#,double,decimal,C#,Double,Decimal,下面的代码只允许输入整数,但我需要为用户提供输入double(0.00)的选项,而不是只输入整数。有什么建议或修改吗 if (_txStaticPressureUpdate.Trim() == "") { txSystemMessage.Text = "Field 'Static Pressure' is empty. Please enter a valid value."; txSystemMessage.ForeColor = System.Dra

下面的代码只允许输入整数,但我需要为用户提供输入double(0.00)的选项,而不是只输入整数。有什么建议或修改吗

if (_txStaticPressureUpdate.Trim() == "")
    {

        txSystemMessage.Text = "Field 'Static Pressure' is empty. Please enter a valid value.";
        txSystemMessage.ForeColor = System.Drawing.Color.Red;
        return;
    }

    //check that record info entered consists of numbers only / no special characters or letters
    for (int j = 0; j < _txStaticPressureUpdate.Length; j++)
    {
        if (!char.IsControl(_txStaticPressureUpdate[j]))
        {
            txSystemMessage.Text = "Field 'Static Pressure' has an invalid value.";
            txSystemMessage.ForeColor = System.Drawing.Color.Red;
            return;
        }
        else
        {
            staticPressure = double.Parse(txStaticPressureUpdate.Text.Trim());
        }
    }
if(_txStaticPressureUpdate.Trim()==“”)
{
txSystemMessage.Text=“字段‘静压’为空。请输入有效值。”;
txSystemMessage.ForeColor=System.Drawing.Color.Red;
返回;
}
//检查输入的记录信息是否仅包含数字/无特殊字符或字母
对于(int j=0;j<_txStaticPressureUpdate.Length;j++)
{
如果(!char.IsControl(_txStaticPressureUpdate[j]))
{
txSystemMessage.Text=“字段‘静压’的值无效。”;
txSystemMessage.ForeColor=System.Drawing.Color.Red;
返回;
}
其他的
{
staticPressure=double.Parse(txStaticPressureUpdate.Text.Trim());
}
}

我正在一个ASPX/C#网站上工作。许多可用选项都适用于WinForms。它仍然有效,但为了更精确地显示公式的最终结果,我希望使用double。

double.TryParse可用于检查输入的字符串是否为double。它返回一个bool,指示解析是否成功,并将解析后的值传递给变量

例如


您也不需要循环检查单个字符。

double.TryParse可用于检查输入的字符串是否为double。它返回一个bool,指示解析是否成功,并将解析后的值传递给变量

例如


您也不需要循环检查各个字符。

太棒了!太谢谢你了,詹姆斯太棒了!那确实非常有效!精彩的!太谢谢你了,詹姆斯太棒了!那确实非常有效!
    if (!double.TryParse(_txStaticPressureUpdate.Text.Trim(), out staticPressure))
    {
        txSystemMessage.Text = "Field 'Static Pressure' has an invalid value.";
        txSystemMessage.ForeColor = System.Drawing.Color.Red;
        return;
    }