函数保持减法而不是除法

Function Keeps Subtracting Instead Of Dividing

下面是我的代码

let interestone = 0.0485
let interesttwo = 0.0625
let interestthree = 0.0725
let months: Double = Double(leasingTextField.text!)!
if months <= 24 {
    rentePercentLabel.text = String(format: "%.2f%%", 4.85)
    renteLabel.text = String(interestone * (price - payouttwo) / 12 * months)
    totalCostsLabel.text = String(price + (interestone * (price - payouttwo) / 12 * months))
    leasingafgiftLabel.text = String(payouttwo + restsumtwo +
        (interestone * (price - payouttwo) / 12 * months) / months)
}

下面这行给我带来了麻烦,因为不是执行两个方程式然后除以最后的月份,而是先添加 payouttwo 和 restsumtwo,然后再添加下一部分。

leasingafgiftLabel.text = String(payouttwo + restsumtwo + 
    (interestone * (price - payouttwo) / 12 * months / months))

我想你可以试试这个...

let interestone = 0.0485
let interesttwo = 0.0625
let interestthree = 0.0725
let months: Double = Double(leasingTextField.text!)!
if months <= 24 {
    rentePercentLabel.text = String(format: "%.2f%%", 4.85)
    let renteLabelValue = interestone * (price - payouttwo) / 12 * months
    renteLabel.text = String(renteLabelValue)
    totalCostsLabel.text = String(price + (interestone * (price - payouttwo) / 12 * months))
    leasingafgiftLabel.text = String((payouttwo + restsumtwo + renteLabelValue) / months)
}

我从那行了解到它无法像您期望的那样计算值,我们可以先计算方程的一部分,然后在实际方程中使用它。