Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Division questions
#1
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!
Reply


Messages In This Thread
Division questions - by Dionysis - Feb-13-2023, 10:27 PM
RE: Division questions - by Larz60+ - Feb-13-2023, 11:05 PM
RE: Division questions - by bowlofred - Feb-13-2023, 11:13 PM
RE: Division questions - by Dionysis - Feb-14-2023, 02:02 PM
RE: Division questions - by deanhystad - Feb-13-2023, 11:35 PM
RE: Division questions - by Larz60+ - Feb-14-2023, 11:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Division by zero and value of argument Lawu 5 8,490 Jul-01-2022, 02:28 PM
Last Post: Lawu
  Floor division problem with plotting x-axis tick labels Mark17 5 3,834 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Division calcuation with answers to 1decimal place. sik 3 3,023 Jul-15-2021, 08:15 AM
Last Post: DeaD_EyE
  Floor division return value Chirumer 8 6,255 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE
  Integer division plozaq 2 2,859 Sep-28-2020, 05:49 PM
Last Post: plozaq
  Overcoming ZeroDivisionError: division by zero Error dgrunwal 8 7,910 Jun-12-2020, 01:52 PM
Last Post: dgrunwal
  Division of an integer into sub-numbers Richard_SS 4 4,311 Jun-14-2019, 11:47 AM
Last Post: DeaD_EyE
  Logic of using floor division and modulus for a different variable at different time SB_J 2 3,447 Nov-01-2018, 07:25 PM
Last Post: SB_J
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 56,792 Nov-25-2017, 06:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020