Feb-13-2023, 10:27 PM
I'm new to Python and also refreshing my math...
I have two questions:
- Simple division (/) gives floats even if the result can be a round integer. Why is that? And how can I get a round integer instead of a .0 float? i.e. get the result 2/2=1 instead of 2/2=1.0 I'm not talking about integer division here, because when there is a decimal part I would like to see it. I.e. show a decimal part when it is not .0 Obviously this is relevant when dividing variables where the result is not know if will have a decimal part or not.
- In integer division (//) with one negative number, why is the result rounded down? i.e. why 10//-3=-4?
Thank you!
I have two questions:
- Simple division (/) gives floats even if the result can be a round integer. Why is that? And how can I get a round integer instead of a .0 float? i.e. get the result 2/2=1 instead of 2/2=1.0 I'm not talking about integer division here, because when there is a decimal part I would like to see it. I.e. show a decimal part when it is not .0 Obviously this is relevant when dividing variables where the result is not know if will have a decimal part or not.
- In integer division (//) with one negative number, why is the result rounded down? i.e. why 10//-3=-4?
Thank you!