How can we round off a number to the nearest 10 in php?
Say I have 23, what code would I use to round it off to 30?
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.
floor()will go down.ceil()will go up.round()will go to nearest by default.Divide by 10, do the ceil, then multiply by 10 to reduce the significant digits.
Edit: I’ve been doing it this way for so long.. but TallGreenTree’s answer is cleaner.