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

How to get the arclen between two curve points in Maya? -

C++ Linked List -

git svn - Unignore directories in git-svn (adding directories to a sparse checkout) -