Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

AndreBarbosa

I just don't know where to use int or float, so, when in doubt I use float. Am I right?

  • one year ago
  • one year ago

  • This Question is Open
  1. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 4

    int is for integer values when you know that you won't have decimal places. for example a counter for quantities that do need decimal precision (like money or distance) you should use float does that make sense?

    • one year ago
  2. EricBerlin
    Best Response
    You've already chosen the best response.
    Medals 0

    "When in doubt, use float" has been exactly my strategy, though I do grasp the differences between them, as described by Chris.

    • one year ago
  3. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    You're pretty much right. Floats are basically scientific notation in binary. There are some values that they can't hit exactly. This can cause some interesting issues in comparison ( == ) statements.

    • one year ago
  4. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    ints are standard and should be used when in doubt. They are 1, 2, 3, etc. Int ranges up to 2 million I believe. Floats also know as "Singles" as 32 bit decimal numbers 1.0, 2.4, 2.3242343242342343, etc. Double's are 64-bit floats.

    • one year ago
  5. irfans
    Best Response
    You've already chosen the best response.
    Medals 0

    If you are doing math operation it is good idea to use floats, but anywhere else it is better to use int.

    • one year ago
  6. akmohamm
    Best Response
    You've already chosen the best response.
    Medals 0

    float and int have a difference purposes. Float when you know for sure you will need it. For example lets say you have a variable you are going to use for a loop or comparision later in the program its better to use int and if needed a float value of that convert it.

    • one year ago
  7. sdoradus
    Best Response
    You've already chosen the best response.
    Medals 1

    Did you see lecture 2 video? Basically, BEWARE of using integers with division. With floats, 3.0 / 2.0 is 1.5. But 3/2 returns 1. As the lecturer pointed out, this is a trap for Python newbies because dividing one integer by another (like 3/2) is done with an integer result!

    • one year ago
  8. hook
    Best Response
    You've already chosen the best response.
    Medals 0

    Remember that with Python 3.0 this dilemma is solved since it automatically uses float when a float could occur in the results. You can still override this by using e.g. `//` for integer (instead of float) division.

    • one year ago
  9. Dean.Shyy
    Best Response
    You've already chosen the best response.
    Medals 0

    Int is an integer and float is a decimal. Right?

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.