我正在创建一个模型,我希望所有的小数值最终都保留 2 位小数(货币)。这就是我的想法,但显然行不通。
public class Fees
{
public decimal permitFee { set; get { return Math.Round(permitFee, 2); } }
public decimal planReviewFee { set; get { return Math.Round(planReviewFee, 2); } }
public decimal surchargeFee { set; get { return Math.Round(surchargeFee, 2); } }
public decimal totalFee { get { return permitFee + planReviewFee + surchargeFee; } }
}
我应该如何设置我的对象以获得正确的输出值?
最佳答案
我认为您不能使用这样的属性(返回自身)。尝试为该属性使用基础变量,看看是否能解决您的问题。
关于c# - 从模型中获取特定的十进制长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10623242/