Round a number

To round a number use the following code:

CGFloat variable = ...CGFloat result = round(variable * 1000.0) / 1000.0;

or

CGFloat variable = round(variable * 1000.0) / 1000.0;[/code]

Use 1000 for 3decimal places, 100 for 2 etc!

Published on

Filled under

Discuss!

comments powered by Disqus