目前我正在从 web 服务中提取数据并将数据填充到自定义对象中。
我正在存储小数,例如 4.56 等。
我对 NSDecimal 和 NSDecimalNumber 有点困惑。我读过 NSDecimalNumber 在处理金钱时应该使用,我就是这样。所以问题是我的属性应该是 NSDecimal 还是 NSDecimalNumber。我已经阅读了您的模型将是 NSDecimal 并且您将使用 NSDecimalNumber 进行任何带有数字的算术的案例。
我基本上想在ObjectiveC中创建这样的行为
private decimal thirtyYear;
public decimal getThirtyYear(){
return thirtyYear/100.0;
}
public void setThrityYear(decimal rate){
thirtyYear = rate;
}
那么,我的 30 年属性应该是 NSDecimal 还是 NSDecimalNumber。此外,在 getThirtyYear() 方法中进行除法时,我应该使用 NSDecimalNumber 进行算术运算。