Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. convert double to Integer?????????

convert double to Integer?????????

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wow9999
    wrote on last edited by
    #1

    Hi there How to convert double to int? Q1: if a double is smaller than 1.4, it will be assign to 1 Ex: 1.3 will be 1 if a double is bigger than 1.4, it will be assign to 2 Ex: 1.5 will be 2 Q2: if a double is bigger than 1 and smaller than 2, it will be assign to 2 Ex: 1.20 will be 2 2.10 will be 3 Does anyone know the function? Thanks.

    A J 2 Replies Last reply
    0
    • W wow9999

      Hi there How to convert double to int? Q1: if a double is smaller than 1.4, it will be assign to 1 Ex: 1.3 will be 1 if a double is bigger than 1.4, it will be assign to 2 Ex: 1.5 will be 2 Q2: if a double is bigger than 1 and smaller than 2, it will be assign to 2 Ex: 1.20 will be 2 2.10 will be 3 Does anyone know the function? Thanks.

      A Offline
      A Offline
      alex barylski
      wrote on last edited by
      #2

      Can't u use a cast? The word of the day is legs, let's go back to my house and spread the word ;P

      1 Reply Last reply
      0
      • W wow9999

        Hi there How to convert double to int? Q1: if a double is smaller than 1.4, it will be assign to 1 Ex: 1.3 will be 1 if a double is bigger than 1.4, it will be assign to 2 Ex: 1.5 will be 2 Q2: if a double is bigger than 1 and smaller than 2, it will be assign to 2 Ex: 1.20 will be 2 2.10 will be 3 Does anyone know the function? Thanks.

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #3

        Q1: Add 0.5 and cast to int. Q2: (rounding up) is done bey ceil() (and ronding down by floor()).


        "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups