I have been trying to use a variable as a specifer in float precision to try to limit the number of decimal places shown for pi:
num = float(input("What decimal point do you want pi to be displayed to?(Up to 15) "))
print(format(math.pi, '.(num)f'))
when i run it, it shows the ValueError: Format specifier missing precision
I was wondering if there was any other way of writing it so i would be able to use a variable. Im pretty new and its probably a really simple mistake, but i dont know.
Thanks for any help :D
you can just pass it in as a format argument ...
num="3"
print("{pi:0.{num}f}".format(pi=22/7.0,num=num))
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