Search code examples
pythonpandasfloating-pointdecimalvalueerror

python variable float format # ValueError: Format specifier missing precision


a = 0.000004545  # variable decimal . 

decimalNumber = 3  # decimal place

print(f' {a:.2f}') # Word Fine

print(f' {a:.decimalNumberf}') # ValueError: Format specifier missing precision

a = variable float number. Sometimes 4 decimal sometimes 8 . How can i fix it this problem ?

Thanks.


Solution

  • You can use format instead of f-string:

    print("{}".format(round(a, decimalNumberf)))