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
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
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.
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}â
thank you for the news
And the right answer would be:
fâ{var:.2f}â
and a good tutorial on the new formating