Reputation: 921
how to trim decimal part in given string of a decimal value in C#. im getting 20472.060 desired o/p - 20472
decimal totalamountWithTaxes = pri + result1 + result2 ;
string totalAmountPlusTaxes = totalamountWithTaxes.ToString();
Upvotes: 4
Views: 20983
Reputation: 117
Int32 Amount = Convert.ToInt32(totalamountWithTaxes.ToString().Substring(0,totalamountWithTaxes.ToString().IndexOf(".")));
Upvotes: 2
Reputation: 183
Yes the above example is right and also I recommend you to visit: String.Format Method-MSDN
Upvotes: 0
Reputation: 172628
You can simply do it like this:
int number = (int) totalAmountPlusTaxes;
or
string totalAmountPlusTaxes = String.Format("{0:C0}",totalamountWithTaxes);
Upvotes: 7