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
Post a Comment