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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -