Reputation: 10839
How to take away fraction part while formatting decimal type in C#?
decimal a = 1.00m;
String.Format("{0}", a); // result is 1.00 Should be 1, HOW?
Upvotes: 2
Views: 4575
Reputation: 6159
Try this:
String.Format("{0:0}", a);
read more here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
Upvotes: 0
Reputation: 91726
You can use:
String.Format("{0:N0}", a); // "1"
Or, to display 1 decimal point:
String.Format("{0:N1}", a); // "1.0"
More info on Standard Numeric Format Strings.
Upvotes: 7
Reputation: 15397
You could always Floor it:
String.Format("{0}", Math.Floor(a));
Or, since there's nothing else in this Format
line, just go this way:
Math.Floor(a).ToString();
Upvotes: 4