Question

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?
Was it helpful?

Solution

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.

OTHER TIPS

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();

Try this:

String.Format("{0:0}", a);

read more here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top