Hi guys, I'm a complete noob when it comes to Swift but I would appreciate any help.
The input value is set to be a float, but when displaying the calc results, I need it to be decimal style AND rounded up to the nearest 0.01.
It currently rounds off to the nearest 3 decimals, but I need it to be two decimals.
My code currently:
func roundUp(number: Float, toNearest: Float) -> Float {
return ceil(number / toNearest) * toNearest
}
let income = grossin - LocalGrossIncomeArray[5] + IntrestSAArray[3] - LocalGrossIncomeArray[9] - LocalGrossIncomeArray[8]
roundUp(income, toNearest: 0.1)
print("Income Round up value = \(income)")
roundUp(grossin, toNearest: 0.1)
print("grossin Round up value = \(grossin)")
let numberFormatterIncome = NSNumberFormatter()
numberFormatterIncome.numberStyle = .DecimalStyle
IncomeLbl.text = "R "
IncomeLbl.text = IncomeLbl.text! + numberFormatterIncome.stringFromNumber(income)!
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = .DecimalStyle
GrossIncome.text = "R "
GrossIncome.text = GrossIncome.text! + numberFormatter.stringFromNumber(Double(grossin))!