0

I am using Python 3.6.5. As a part of a problem I had to do 0.6/0.1. But the output I am getting is different:

0.6/0.1

5.999999999999999

Also I checked other numbers , this is what happens

0.4/0.1

4.0

0.5/0.1

5.0

0.6/0.1

5.999999999999999

0.7/0.1

6.999999999999999

0.8/0.1

8.0

0.9/0.1

9.0

0.99/0.1

9.899999999999999

0.89/0.1

8.9

0.79/0.1

7.9

0.69/0.1

6.8999999999999995

0.59/0.1

5.8999999999999995

0.49/0.1

4.8999999999999995

0.39/0.1

3.9

Am I doing something wrong or is this a bug.Why are the output for 0.6/0.1 and 0.5/0.1 in different formats and how to work around this

cikihovad
  • 11
  • 2
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [On topic](http://stackoverflow.com/help/on-topic), [how to ask](http://stackoverflow.com/help/how-to-ask), and [... the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) apply here. – Prune Aug 20 '18 at 16:34
  • In particular, your edit "how to work around this" is unclear. Describe what you expect to achieve as output, with reference to the materials linked when this question was correctly marked as a duplicate. – Prune Aug 20 '18 at 16:35
  • I am looking for some function or library that would allow me to get the correct answer just as the link showed using Math.sum for Javascript – cikihovad Aug 20 '18 at 16:57
  • If you Google the phrase "Python decimal arithmetic", you’ll find tutorials that can explain it much better than we can in an answer here. – Prune Aug 20 '18 at 17:27
  • Thanks.For the sake of completion one way is : >>> from decimal import * >>>float(Decimal(.49)/Decimal(0.1)) – cikihovad Aug 20 '18 at 17:46

0 Answers0