krishna mohan
krishna mohan

Reputation: 921

How remove decimal part from string?

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

Answers (3)

Riches Picker
Riches Picker

Reputation: 117

Int32 Amount = Convert.ToInt32(totalamountWithTaxes.ToString().Substring(0,totalamountWithTaxes.ToString().IndexOf(".")));

Upvotes: 2

Surya
Surya

Reputation: 183

Yes the above example is right and also I recommend you to visit: String.Format Method-MSDN

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172628

You can simply do it like this:

int number = (int) totalAmountPlusTaxes;

or

string totalAmountPlusTaxes = String.Format("{0:C0}",totalamountWithTaxes);

Upvotes: 7

Related Questions