You can use the round
function, which takes as its first argument the number and the second argument is the precision after the decimal point.
In your case, it would be:
answer = str(round(answer, 2))
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 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?
- Round to nearest 0.05 using Python
- using Python logger class to generate multiple logs for different log levels
- multiprocessing.pool.MaybeEncodingError: ‘TypeError(“cannot serialize ‘_io.BufferedReader’ object”,)’