#π Why is this a float and not and integer? Line 19. In-depth explanation for a beginner needed :)
15 messages Β· Page 1 of 1 (latest)
@bold aspen
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Because you are adding two floats together
Even if it was one float and an integer, it will stay a float
THANK YOU
operations involving floats can also be slightly off due to precision issues, for example 0.3 + 0.3 + 0.3 + 0.1 is not exactly equal to 1.0
THANKS π
oh yeah and if you want precision on decimal operations @bold aspen should use decimal.Decimal
fraction.Fraction is just as precise and may be easier to reason with in some applications. π
I forgot that existed, but yeah. Both decimals and floats can be represented losslessly as fractions but not vice versa.
@bold aspen - for more detail, take a look at some content on number types . Here's the official doc version - https://python-basics-tutorial.readthedocs.io/en/latest/types/numbers/index.html
I've got a book called "Learning Python 5th edition" which does a great job of explaining the number types.
In my opinion they should make fractions built-in and call it something like num as the first choice that new python users use (and only use floats and ints) when necessary. Removes so much confusion over the accuracy of floats...
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.