I’ve been searching for a way in python to get only 4 digits on the right of the comma of a decimal number, but i couldn’t find. Took a look on this post,—> Rounding decimals with new Python format function
,but the function written there…
>>> n = 4
>>> p = math.pi
>>> '{0:.{1}f}'.format(p, n)
'3.1416'
…seems not to work in my case.
I imported the modules “math” and “decimal”, but maybe i’m missing some others to import, but i don’t know which of them to import.
Thanks everyone, and sorry if this issue has already been posted.
Peixe
I know its using the old syntax but I personally prefer it.