In my iPhone app I need to round an integer to the nearest multiple of 5.
E.g. Round 6 to = 10 and round 23 to = 25 etc
Edit
I forgot to say, I only want to round up! In all situations, so 22 would round up to 25 for example.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to always round up, you can use the following:
If
acan be a float, you should add a cast tointas follows:Note that you can use the function
ceilto accomplish the same result:Old Answer:
To round to the nearest multiple of
5, you can do the following: