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)") 

this playground result may give more understanding: enter image description here


Comments

Popular posts from this blog

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -