Krishna Mohan
Krishna Mohan

Reputation: 315

getting error while multiplying two numbers in c#

I am unable to find the service tax of a product. How do I get the service tax of a product? Should I use decimal or double? while using double its not giving error.

string StrVatPercentage = vatPercentage.Text;

decimal totalprice = Convert.ToDecimal(qty) * Convert.ToDecimal(price);
    // totalprice = 497080M // qty = 4 // price= 124,270.00

decimal serviceTaxPrice = totalprice * Convert.ToDecimal(StrVatPercentage)/100;
    // strVtPercentage=12.36M- getting error in this line

Upvotes: 0

Views: 169

Answers (1)

JSON
JSON

Reputation: 1182

I believe the problem is in the value you have for StrVatPercentage. You say it is equal to "12.36m-". This will not convert because it is in the incorrect format. I run this

 decimal totalprice = Convert.ToDecimal("4") * Convert.ToDecimal("124,270.00");
 decimal serviceTaxPrice = totalprice * Convert.ToDecimal("12.36") / 100;

And it works just fine.

Upvotes: 3

Related Questions