tags:

views:

830

answers:

2

This is my code:

lExpression = @"convert(" + lNewColName + ",'System.Decimal')";
if (pCurrency.ToString() != "Select")
  lExpression += " * convert(" + pCurrency.ToString() + ",'System.Decimal')";
mDtCases.Columns[lColName].Expression = lExpression;

Where lNewColName is the ColumnName, pCurrency is the Currency Combo Box, mDtCases is datagrid. When this is run, it displays 213.2365. I want it to display 213.24.

Please help me.

A: 
System.Convert.ToDouble(IExpression)

http://msdn.microsoft.com/en-us/library/w2zyd0fa.aspx

Math.Round( double, int )

http://msdn.microsoft.com/fr-fr/library/zy06z30k.aspx

belaz
+1  A: 

The syntax for an Expression supports a number of simple functions including aggregates, but doesn't support rounding as such.

However you can round the displayed value by formatting with the required number of decimals. You don't say what DataGrid you are using, but for a Web UI you can format using e.g. the BoundColumn.DataFormatString property, and for a WinForms UI using the DataGridTextBoxColumn.Format property.

Joe