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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -