How Do I Limit Decimals To Only Two Decimals In Python

round to two decimal places python
>>> x = 13.949999999999999999
>>> x
13.95
>>> g = float("{0:.2f}".format(x))
>>> g
13.95
>>> x == g
True
>>> h = round(x, 2)
>>> h
13.95
>>> x == h
True
how do i limit decimals to only two decimals in python
answer = str(round(answer, 2))

Leave a Comment