how to show numbers in 0, 1, 2, 3, 4 decimal places in a GridView?
When you have a GridView control and you bind it to a decimal field (for example), you can manipulate the format of the string shown by using the format specifier in the BoundField or in the Eval function in the TemplateField.
Here’s how you do it. Use the f with a number such as f0 for no decimal places, f2 for 2 decimal places and so on so forth.
<asp:BoundField DataField=”prodPrice” HeaderText=”Price” HtmlEncode=”False” DataFormatString=”{0:f0}” />
Or in TemplateField
<asp:TemplateField HeaderText=”Price”>
<ItemTemplate>
<%#Eval(“prodPrice”,”{0:f0}”)%>
</ItemTemplate>
</asp:TemplateField>
You can change the f<number> to any value to get numbers like 2 with f0 and 2.0 with f1 and 2.00 with f2 and so on…


Very Good Answer!!!!
Good tips. I was wondering if I could do it in the way {0:c} works for currency. Now got it. Thanks.
Its always a pleasure. Thanks for dropping by.
It helped.. keep it up.
Appreciate the comment. Thanks