def round_to(n, precision):
correction = 0.5 if n >= 0 else -0.5
return int( n/precision+correction ) * precision
def round_to_05(n):
return round_to(n, 0.05)
More Related Contents:
- Need a python module for numerical and scientific computing other than NumPy and SciPy
- round function not working in python
- Python 3.x rounding behavior
- How to round to 2 decimals with Python?
- How to round a number to significant figures in Python
- How do you round UP a number?
- Limiting floats to two decimal points
- Round to 5 (or other number) in Python
- Python round up integer to next hundred
- How to properly round-up half float numbers?
- round() doesn’t seem to be rounding properly
- How to round the minute of a datetime object
- Round float to x decimals?
- Pandas read csv file with float values results in weird rounding and decimal digits
- Round up to Second Decimal Place in Python
- rounding errors in Python floor division
- Rounding a number in Python but keeping ending zeros
- Rounding to two decimal places in Python 2.7?
- round down to 2 decimal in python
- Round each number in a Python pandas data frame by 2 decimals
- Python – Rounding by quarter-intervals
- How to round values only for display in pandas while retaining original ones in the dataframe?
- Why does the floating-point value of 4*0.1 look nice in Python 3 but 3*0.1 doesn’t?
- Rounding error in Python with non-odd number? [duplicate]
- How to pad a string with leading zeros in Python 3 [duplicate]
- Round a floating-point number down to the nearest integer?
- In Python, what is a good way to round towards zero in integer division?
- How to eliminate the extra minus sign when rounding negative numbers towards zero in numpy?
- Changing one character in a string
- pandas: merge (join) two data frames on multiple columns