Query linq calculatefield and decimal ?

  • Thread starter Thread starter ChristopheBe
  • Start date Start date
C

ChristopheBe

Guest
Hi all,

i have a little problem with formatting a calculate field ..

i have class for example and i do some calculation on some field and place the result in a grid view

But the result is for example => 8.75155685 but i want 8.75

here is it a sample :

public class Stats
{
public int ID { get; set; }
public Decimal amount1 { get; set; }
public Decimal amount2 { get; set; }

}



Here i create a object stats with some value

List<Stats> myList = new List<Stats>();

Stats oneStats = new Stats();
oneStats.ID = 1;
oneStats.amount1 = Convert.ToDecimal("18,2");
oneStats.amount2 = Convert.ToDecimal("25,25");

//
myList.Add(oneStats);



at the end i create a linq query and assign result in a data grid view


var datas = from x in myList
selectnew{ Actuel = ((x.amount1 / x.amount2) * 100)};

//
dataGridView1.DataSource = datas.ToList();




for the example the result is : 72,079207920792079207920792080

but i want 72,07 ..


how i can format the calculate field ?

thanks for your time


Were going to the wall in belgium !

Continue reading...
 
Back
Top