func solveForPayment( amount currency.Amount, rate float64, length int) currency.Amount { amountF := amount.Float64() if rate == 0.0 { return amount.FromFloat64(amountF / float64(length)) } result := amount.FromFloat64(amountF * rate * (1.0 + 1.0/(math.Pow((1.0+rate), float64(length))-1.0))) resultI := result.Int64() if resultI <= 0 { resultI = 1 } interestOnly := amount.FromFloat64(amountF * rate).Int64() if resultI <= interestOnly { resultI = interestOnly + 1 } return result.FromInt64(resultI) }