我想将 6% 的增量添加到查询的 return 结果
i want to add increment of 6% to the return result from the query
<td>
<strong>
Rs @(Model.lstItem.Sum(c => c._product.option != null
? (c._product.option.Price * c.Quantity)
: (c._product.product.Price * c.Quantity))
- (Model.coupon != null ? (int)Model.coupon.Discount : 0))
</strong>
</td>
首先让我告诉你我是 asp.net mvc 的新手..
现在我的问题是我有上面的查询,它在乘以价格和数量后返回总计。现在我想要的是我想将 pricequantity 的 6% 增加到 pricequanity..
最终结果将是(价格 * 数量)+ 价格的 6% * 数量..
希望大家理解我的问题
你可以这样做:
(price * quantity) + (((price * quantity)/100) * 6))
您不应该将这些 constants
保留在 View
中。如果您在多个地方进行这些计算,并且您希望将来将百分比更改为 7%,则必须在所有地方进行更改。因此,它应该来自您的数据库、配置文件或常量 class。
因此,最简单的方法是在 Common
文件夹或 Utility
文件夹中创建一个名为 ApplicationConstants
的静态 class。
public static class ApplicationConstants
{
public const int ProfitPercentage = 6;
}
然后在你的 View
,
@using YourAppName.Common
<td>
<strong>
Rs @(
(1 + ApplicationConstants.ProfitPercentage / 100) *
(Model.lstItem.Sum(c => c._product.option != null
? (c._product.option.Price * c.Quantity)
: (c._product.product.Price * c.Quantity)))
- (Model.coupon != null ? (int)Model.coupon.Discount : 0))
</strong>
</td>
<td>
<strong>
Rs @(Model.lstItem.Sum(c => c._product.option != null
? (c._product.option.Price * c.Quantity)
: (c._product.product.Price * c.Quantity))
- (Model.coupon != null ? (int)Model.coupon.Discount : 0))
</strong>
</td>
首先让我告诉你我是 asp.net mvc 的新手.. 现在我的问题是我有上面的查询,它在乘以价格和数量后返回总计。现在我想要的是我想将 pricequantity 的 6% 增加到 pricequanity..
最终结果将是(价格 * 数量)+ 价格的 6% * 数量..
希望大家理解我的问题
你可以这样做:
(price * quantity) + (((price * quantity)/100) * 6))
您不应该将这些 constants
保留在 View
中。如果您在多个地方进行这些计算,并且您希望将来将百分比更改为 7%,则必须在所有地方进行更改。因此,它应该来自您的数据库、配置文件或常量 class。
因此,最简单的方法是在 Common
文件夹或 Utility
文件夹中创建一个名为 ApplicationConstants
的静态 class。
public static class ApplicationConstants
{
public const int ProfitPercentage = 6;
}
然后在你的 View
,
@using YourAppName.Common
<td>
<strong>
Rs @(
(1 + ApplicationConstants.ProfitPercentage / 100) *
(Model.lstItem.Sum(c => c._product.option != null
? (c._product.option.Price * c.Quantity)
: (c._product.product.Price * c.Quantity)))
- (Model.coupon != null ? (int)Model.coupon.Discount : 0))
</strong>
</td>