【问题标题】:Linq Sum Group by without decimalsLinq Sum Group by 不带小数
【发布时间】:2016-05-24 04:41:58
【问题描述】:

我有这个由 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" />
                                        }

【问题讨论】:

    标签: c# decimal number-formatting


    【解决方案1】:

    根据“向上取整”的含义,您可以使用Decimal.Round()Math.Floor()Math.Ceiling()

    Total = Decimal.Round(z.Sum(l => l.Total), 0);
    

    【讨论】:

    • 非常感谢这是我一直在寻找的方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2023-03-05
    • 2012-12-08
    相关资源
    最近更新 更多