I want to set precision of a long float number to 2 decimal places. Rounding the number, truncating, floor,etc. won't work. For example my number is 5.196152422706632 . I want it as 5.19 and not 5 or 5.2,etc. I want to simply remove all other digits. How should i do it?
Asked
Active
Viewed 85 times
0
-
1Use a `Decimal`? – jonrsharpe Sep 30 '19 at 16:23
-
So is this result returned in a function call, or is it stored in a variable that you need to print? Please post your sample code – shuberman Sep 30 '19 at 16:23
-
you should refer to this webpage for more help - https://www.geeksforgeeks.org/precision-handling-python/ – shuberman Sep 30 '19 at 16:25
-
Possible duplicate of [Truncate to three decimals in Python](https://stackoverflow.com/questions/8595973/truncate-to-three-decimals-in-python) – 8888 Sep 30 '19 at 16:28
-
See the truncate function in the [answer](https://stackoverflow.com/a/37697840/14167). – David Nehme Sep 30 '19 at 16:31
-
Thanks for your replies. But i have tried all of them. But they seem to round off at some point. That is I don't get desired result every time especially truncate(). – Oct 01 '19 at 16:23