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

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -