How do I round numbers up or down depending on the value in object C.. for example.
Lets say the number is 143 – I would want to round down to 140
but if the number is 146 – I would want to round up to 150
any suggestions?
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.
Assuming 145 should round to 150 (that’s the standard in science and technology), the formula is:
More generally, when rounding to the nearest n, it’s
It comes from the fact that integer division always rounds down.
For negative numbers, it’s slightly more tricky.
EDIT: also assuming it’s all integers. With floats/doubles, better use the C math library, as division works differently. Like this: