Computer Science Canada How does Rounding work in Python? |
Author: | Planet_Fall [ Tue Jan 21, 2014 7:15 pm ] | ||
Post subject: | How does Rounding work in Python? | ||
I have statistic homework, and I was making a program to find the class intervals but the final answer needs to be rounded up to the nearest 10 or 5. How would I do this?
|
Author: | Dreadnought [ Tue Jan 21, 2014 8:34 pm ] |
Post subject: | Re: How does Rounding work in Python? |
You can use the round function to round floating point numbers to any number of digits after the decimal point (you can use negative numbers to round to digits before the decimal point). So this lets you round to the nearest multiple of any power of ten you want. To round to the nearest multiple of any other number just divide by this number, round, then multiply by the number. |