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.

0

1 Answer 1

-2

You can use format instead of f-string:

print("{}".format(round(a, decimalNumberf)))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.