-4

precise decimal digit without using round()

I am using python3 and django 1.11.5

Suppose a = 92.466578699

Expected result a = 92.46657

  • 1
    Output where? On the console, as a string? And why not `92.46658`, shouldn't it be rounded up? And how is django relevant, you want to round it in the template? – user2390182 Oct 11 '19 at 20:10
  • 1
    Possible duplicate of [Limiting floats to two decimal points](https://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points) – rdas Oct 11 '19 at 20:10
  • @ schwobaseggl: Thanks for your response . Actually I have to compare two outputs but they are different at 10 decimal digit . Suppose a = 92.466578698 and b = 92.466578699. I want to check the output upto 8 decimal limit which will solve my issue. – isha thakur Oct 11 '19 at 20:15
  • https://docs.python.org/3/library/math.html#math.isclose might be useful – user2390182 Oct 11 '19 at 20:17
  • Is there a reason you do not want to use round? – C. Fennell Oct 11 '19 at 21:53
  • Yes, C. Lewis. I have already mentioned above as " I have to compare two outputs but they are different at 10 decimal digit . Suppose a = 92.466578698 and b = 92.466578699. I want to check the output upto 8 decimal limit which will solve my issue" – isha thakur Oct 15 '19 at 02:10
  • @user2412309 answered my question. Thanks everyone for your participation. – isha thakur Oct 15 '19 at 02:12

1 Answers1

1

Try format

format(1.242563,".2f")

The output would be:

1.33243         

Another

 print (format(1.332432,".5f"))
 1.33243