let amount:Float = 2.235
print("\(roundf(self.amountTax * 100) / 100)")
it returns 2.23
but it should be 2.24
let amount:Float = 2.235
print("\(roundf(self.amountTax * 100) / 100)")
it returns 2.23
but it should be 2.24
The result is 2.23
because amount * 100
is 223.5
and the rounding of that is 223
(because 2.235
probably has no exact representation, but is something like 2.234999999999
) , and divided by 100 it results in 2.23
.
You may want to use the ceilf
unction instead:
print("(ceilf(amount * 100) / 100)")