Python Format Float Without Trailing Zeros

August 17, 2019
v = 0.0028

v_str = f"{v:.8f}"
print(v_str)    # 0.00280000

v_str = f"{v:.8f}".rstrip('0').rstrip('.')
print(v_str)    # 0.0028
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.