ASP.NET 2.0 GridView DataFormatString for Amounts (SqlMoney)

I might have discussed this in my blog earlier. However I will like to share my thoughts again.

Check this:

http://community.sgdotnet.org/photos/chuawenching/picture44026.aspx

As you can see, if I don't set the DataFormatString (don't forget to set HtmlEncode="false"), I will get the 1st picture. Why 0.0000 instead of 0.00? Read my earlier posts :)

Since Amount should display the currency values like $0.00 instead of 0.0000. So you should format it as {0:C} or {0:c}. Take note, there is no use if you try this {0:C2}.

You will get your results as you want. Assuming it is based on en-US okay :)

But there are times when customer asks you to place the currency itself that gridview column HeaderText like this "Amount (RM)". RM represents the currency in Malaysia. So there is no point display $0.00.

For DataFormatString on currency, I can't see a way to remove the dollar sign '$'. So to do that, you have to format it to decimal like in 3rd picture using {0:#,##0.00}

Like this, it looks more reasonable and customer will be happy.

Published Thursday, November 02, 2006 9:35 AM by chuawenching

Comments

# re: ASP.NET 2.0 GridView DataFormatString for Amounts (SqlMoney)

Friday, November 03, 2006 12:50 AM by alvinz_c

What about simplified {0:f2} and {0:#,#.00}?

Regards,

Alvin Chooi, Malaysia

Microsoft ASP.NET Enthusiast

http://alvinzc.blogspot.com

# re: ASP.NET 2.0 GridView DataFormatString for Amounts (SqlMoney)

Friday, November 03, 2006 7:35 AM by chuawenching

Hmm.. I never tried {0:f2}, from msdn http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfFormattingNumericResultsTable.asp

It will work too. Even shorter. Cool thanks.

# Francisco

Monday, July 28, 2008 12:44 AM by Gavin

f809609b26c6f4af733a7ad93cb308e4

<a href="njdokj.info/.../f809609b26c6f4af733a7ad93cb308e4">">njdokj.info/.../f809609b26c6f4af733a7ad93cb308e4"> njdokj.info/.../f809609b26c6f4af733a7ad93cb308e4 </a>

njdokj.info/.../f809609b26c6f4af733a7ad93cb308e4

[url]njdokj.info/.../f809609b26c6f4af733a7ad93cb308e4[url]