Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

i have values in grid view is 1234.333333344444444555555512

but due to this its look very horrible, so i need to display value as 1234.33333334444

can anyone help me to do this ..
Posted

1 solution

Use DataFormatString property.
Use 'F or f: Displays numeric values in fixed format. You can specify the number of decimal places.'. For six decimal places:
XML
<asp:BoundField DataField="totaldata" HeaderText="Total Data"
     ReadOnly="True" SortExpression="totaldata" DataFormatString="{0:F6}" />


Details here: BoundField.DataFormatString Property [^]


UPDATE:
If I am correct, all you are doing right now is binding a datatable to a grid and put 'AutoGenerateColumns=true'.

What I am meant by creating bound column is, set AutoGenerateColumns=false and then define the columns as bound columns in your designer. Map the columns to expected fields. Doing this would give you option to format columns. Use DataFormatString for your desired column here.

Alternative:
In case, you don't want to do this, then there is other option too. You can format the value from the source itself OR before binding. So, if you are getting the data from DB, get the data in formatted way such that only 3 decimal is shown. If you are hesitant in doing this at DB level then you can do this in your business logic layer (if it exists!). Just before binding the table to grid, create a foreach loop on the datatable rows. For the column in discussion, get the value and modify/update it as per need. Once the loop is done, you can use the new/updated datatable to bind with grid.
 
Share this answer
 
v3
Comments
surikarthi 5-May-12 2:35am    
hi thank q for your reply but I'm not using any bound fields in grid view..
surikarthi 5-May-12 2:43am    
here i'm binding it through data table values..
Sandeep Mewara 5-May-12 3:34am    
Then bind it! :)

By default you won't get the additional properties.
surikarthi 5-May-12 5:13am    
cha naku telidha anthi...
Sandeep Mewara 5-May-12 5:17am    
Now, I will call that SPAM. So, avoid it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900