Format it to 6 decimal places:
format(value, '.6f')
Demo:
>>> format(2.0, '.6f')
'2.000000'
The format()
function turns values to strings following the formatting instructions given.
More Related Contents:
- Python JSON serialize a Decimal object
- How to get numbers after decimal point?
- Convert hex to float
- Rounding a number in Python but keeping ending zeros
- Clarification on the Decimal type in Python
- Decimal place issues with floats and decimal.Decimal
- How to get largest possible precision? (Python – Decimal)
- How do I parse a string to a float or int?
- How can I force division to be floating point? Division keeps rounding down to 0?
- Formatting floats without trailing zeros
- How to check if a float value is a whole number
- How to truncate float values?
- How to avoid floating point errors? [duplicate]
- How to print float to n decimal places including trailing 0s?
- Python float – str – float weirdness
- Easy way of finding decimal places
- Testing floating point equality
- OverflowError: (34, ‘Result too large’)
- Convert float to string in positional format (without scientific notation and false precision)
- What is the difference between int() and floor() in Python 3?
- How to manage division of huge numbers in Python?
- Determine precision and scale of particular number in Python
- How do I check if a string represents a number (float or int)?
- drop trailing zeros from decimal
- Why do I get “OverflowError: (34, ‘Result too large’)” or “OverflowError: (34, ‘Numerical result out of range’)” from floating-point exponentiation?
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- Number of digits in exponent
- Rounding floats so that they sum to precisely 1
- Round a floating-point number down to the nearest integer?
- mean from pandas and numpy differ