0
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.

konstantin_doncov
  • 2,725
  • 4
  • 40
  • 100
Kintsugi
  • 21
  • 1
  • 4

1 Answers1

-2

You can use format instead of f-string:

print("{}".format(round(a, decimalNumberf)))
Bruno Mello
  • 4,448
  • 1
  • 9
  • 39