How to correct decimal places?

Hi
How can I correct the decimal places to two.?

For eg:
0.89674 to 0.89

I tried the round function from python but not working.

Thanks
Arun

Hello,
You have to use number to string format, here is one link to extensive explanation
https://pyformat.info/#number_padding
you can use that
var = 0.89674
res = ‘{:04.3f}’.format(var)
print(res)
0.897

1 Like

Another way is to multiply by 10^x, round and then divide by 10^x where X is the numer of decimal points you want.

1 Like

Yet another way to do the above is the new Python f-string format which is a new favorite of mine:

f’{var:04.3}’

1 Like

thank you for the news
And the right answer would be:
f’{var:.2f}’
and a good tutorial on the new formating