How to accept values as doubles in a textbox in ASPX C# Website? -


the following code allows enter integers, instead of integers, need give option user enter double (0.00). suggestions or modification?

if (_txstaticpressureupdate.trim() == "")     {          txsystemmessage.text = "field 'static pressure' empty. please enter valid value.";         txsystemmessage.forecolor = system.drawing.color.red;         return;     }      //check record info entered consists of numbers / no special characters or letters     (int j = 0; j < _txstaticpressureupdate.length; j++)     {         if (!char.iscontrol(_txstaticpressureupdate[j]))         {             txsystemmessage.text = "field 'static pressure' has invalid value.";             txsystemmessage.forecolor = system.drawing.color.red;             return;         }         else         {             staticpressure = double.parse(txstaticpressureupdate.text.trim());         }     } 

i working on aspx/c# website. many of options available winforms. sitll works, more precise in final result of formula, use doubles.

double.tryparse used check entered string double. returns bool indicating if parse succeeded, , passes out parsed value variable.

eg.

    if (!double.tryparse(_txstaticpressureupdate.text.trim(), out staticpressure))     {         txsystemmessage.text = "field 'static pressure' has invalid value.";         txsystemmessage.forecolor = system.drawing.color.red;         return;     } 

you won't need loop through , check individual characters either.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -