I need to print double with precision equal exactly to 6, I found function round:
print(str(round(result, 6))
But in case result itself has less precision, the print function skips zeros at the end.
Gor example, the output of such code,
print(str(round(4.0, 6)))
is
4.0
But what I need is
4.000000
How can I reach this?
Try using a format string:
print("%.6f"%4.0) # 4.000000
Or alternatively:
print("{:.6f}".format(4.0))
See the Python documentation for details on format strings and more examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With