Avatar ·

Fixed number of digits after decimal point in Python

📁 Advanced Python Topics, AI

Is there an analogue of the function toFixed() in JS? I need something like this:

>>> a = 12.3456789
>>> a.toFixed(2)
'12.35'
>>> a.toFixed(0)
'12'
>>> b = 12.000001
>>> b.toFixed(3)
'12.000'