Usher
Usher

Reputation: 2146

Data format in gridview for decimal values

I have this column in datagrid view always having decimal value like (1.30) or 1.2 or 1.

I am trying to truncation the decimal value to 1 for example (1.30) should be 1.3.

How is possible to achieve thru Data format in grid view

<asp:BoundField DataField="TGValue" ShowHeader="False">
    <ItemStyle Width="10%" />
</asp:BoundField>

Upvotes: 0

Views: 141

Answers (2)

Brave Soul
Brave Soul

Reputation: 3620

  <asp:BoundField DataField="TGValue" ShowHeader="FALSE" DataFormatString="{0:0.0}" >
  <ItemStyle Width="10%" />
            </asp:BoundField>

Upvotes: 0

Sachin
Sachin

Reputation: 40990

You can use the DataFormatString property to achieve that. You just need to give the proper string format. In your case it would be,

DataFormatString="{0:0.0}"

So your markup would be

<asp:BoundField DataField="TGValue" ShowHeader="False" DataFormatString="{0:0.0}" >
         <ItemStyle Width="10%" />
</asp:BoundField>

Upvotes: 1

Related Questions