Linq Sum Group by 不带小数
Linq Sum Group by without decimals
我有这个 Group by Sum LinQ,但它给我的结果有很多小数,有没有办法将数字四舍五入?不显示小数?
这是我的 LinQ:
@foreach (var item in Model.Select(x => new //here you count your total
{
Rid = x.Rid,
Total = x.Total * x.Cantidad
})
.GroupBy(l => l.Rid) //and then grouping
.Select(z => new
{
Turno = z.Key,
Total = z.Sum(l => l.Total)
}))
{
<input value="@item" />
}
根据 "round up" 的含义,您可以使用 Decimal.Round()
或 Math.Floor()
、Math.Ceiling()
.
Total = Decimal.Round(z.Sum(l => l.Total), 0);
我有这个 Group by Sum LinQ,但它给我的结果有很多小数,有没有办法将数字四舍五入?不显示小数? 这是我的 LinQ:
@foreach (var item in Model.Select(x => new //here you count your total
{
Rid = x.Rid,
Total = x.Total * x.Cantidad
})
.GroupBy(l => l.Rid) //and then grouping
.Select(z => new
{
Turno = z.Key,
Total = z.Sum(l => l.Total)
}))
{
<input value="@item" />
}
根据 "round up" 的含义,您可以使用 Decimal.Round()
或 Math.Floor()
、Math.Ceiling()
.
Total = Decimal.Round(z.Sum(l => l.Total), 0);