textbox - how to solve attempted to divide by zero in c#? -


i getting bug, wrote code below

code:

decimal amnt; decimal.tryparse(txtamnt.text, out amnt); int tnure=1; int.tryparse(txttnre.text, out tnure); txtddctamnt.text = (amnt /tnure).tostring("0.00"); 

when in textbox value 0 getting error.if possible give answer me.

how using if check before dividing zero?

if(tnure != 0)     txtddctamnt.text = (amnt / tnure).tostring("0.00"); else     txtddctamnt.text = "invalid value"; 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -