Pregunta

I want to round down column values after division aplied:

 DataColumn maxSpend = new DataColumn();
    maxSpend.DataType = System.Type.GetType("System.Double");
    maxSpend.Expression = string.Format("{0:0.00} / price", this.maxSpend);

Its possible somehow to use Math.floor() in column expression or are there other solutions for this ?

¿Fue útil?

Solución

.NET functions are not allowed in DataColumn-Expressions. The easiest would be to do it in the first place in the the dbms(if you're using any).

For example in SQL-Server: SELECT FLOOR(MaxSpend/Price)AS MaxSpend ....

The other way is looping through the DataRows. For example:

foreach (DataRow row in tbl.Rows)
{
    double price    = row.Field<double>("price");
    row["maxSpend"] = Math.Floor(this.maxSpend / price);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top