Elad Benda
Elad Benda

Reputation: 36682

Decimal string format truncates the zero left to the decimal point

I'm calling the below method with 0.02

public static string FormatAsDecimalWithCommaSeperator(decimal value)
{
    return String.Format("{0:#,###,###.##}", value);
}

returns .02

All I want to do is to leave two decimal digits and leave the zero left to the decimal point. Meaning in that case it should have returned "0.02"

How can I fix this?

Upvotes: 0

Views: 557

Answers (2)

Balazs Tihanyi
Balazs Tihanyi

Reputation: 6719

Try this:

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

Upvotes: 2

Mr Lister
Mr Lister

Reputation: 46629

You could easily have googled. Here, I found this.

http://www.csharp-examples.net/string-format-double/

So the answer is "{0:#,###,##0.##}"

Upvotes: 2

Related Questions