By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Why this wrong calculation. The output must be 2.1. But it yielded 2.0999999

P: 1
# This code yielded a wrong output


# Output : 2.0999999999999996
Mar 19 '18 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 614
Two articles on floating point calcs on a computer. If you want something more exact check the Decimal module
Mar 20 '18 #2

P: 8
the bottom line is that you should never expect any floating point calculation to yield an exact value. It's not a bug, but an intrinsic tradeoff in the design.
Mar 24 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.