Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all...i want to limit the decimal length of a datagridview column..

Please help me out
Posted

try this
for 2 places of decimal

double.Parse(string.Format("{0:0.00}", Eval("Name").ToString()))

or

double.Parse(Eval("Name").ToString()).ToString("0.00")
 
Share this answer
 
Comments
DileepkumarReddy 17-Nov-12 6:12am    
what is Eval and in which event should i try this...
pryashrma 17-Nov-12 6:59am    
are you asking the query for 'GridView' control
DileepkumarReddy 17-Nov-12 7:14am    
yes
Alternate and easy way:
set the DataFormatString of Databound field
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567

for eg:
DataFormatString ="{0:F3}"

in aspx page design mode
single click on gridView1
then click on ">" of gridView1
then click on 'Edit Columns'
then select respective field and set 'DataFormatString'

you can also view the following link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

please tell me if i m confusing you
 
Share this answer
 
Comments
DileepkumarReddy 17-Nov-12 7:04am    
Actually i am working on windows app.
There is no property DataFormatString..
pryashrma 17-Nov-12 7:57am    
does this line help you-

this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "F3";
pryashrma 17-Nov-12 7:48am    
sorry can't help
Hey there,
Had a similar issue a while back...

VB Code to limit decimal:
Me.DataGridView1.Columns.Item(3).DefaultCellStyle.Format = "n2"

C# Code:
dataGridView2.Columns["Column_Name"].DefaultCellStyle.Format = "n2";
 
Share this answer
 

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