ios - Swift roundf not working with float value -
let amount:float = 2.235 print("\(roundf(self.amounttax * 100) / 100)")
it returns 2.23
but should 2.24
the result 2.23
because amount * 100
223.5
, rounding of 223
(because 2.235
has no exact representation, 2.234999999999
) , , divided 100 results in 2.23
.
you may want use ceilf
unction instead:
print("(ceilf(amount * 100) / 100)")
Comments
Post a Comment