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. problm with float value

problm with float value

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 Posts 2 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.
  • Z Offline
    Z Offline
    Zeeshan Bilal
    wrote on last edited by
    #1

    HI, i want to convert my Answer to float from integer value as in my code follows float k =0.0; int count = 0; CString str; for (int i=30;i <= 1440; ) { k= i/60; /// here problem is //// if i = 90 then result should be 90/60 = 1.50 ////// its gives 1.00 ,, but its should be 1.50 //// in all case of any.50 it gives any.00 str.Format(_T("%d min. or (%2.02f Hrs)"), i , k); m_ctrl.InsertString(count++, str); i= i+30; } i hope u got the problm ,, that is i also need answer in shape of 1.00 , 1.50 , 2.00 , 2.50 etc. but its shows 1.50 , 2,50 ..as 1.00 , 2.00 respectvly. measn it round .50 to lower .00 value thanx

    C 1 Reply Last reply
    0
    • Z Zeeshan Bilal

      HI, i want to convert my Answer to float from integer value as in my code follows float k =0.0; int count = 0; CString str; for (int i=30;i <= 1440; ) { k= i/60; /// here problem is //// if i = 90 then result should be 90/60 = 1.50 ////// its gives 1.00 ,, but its should be 1.50 //// in all case of any.50 it gives any.00 str.Format(_T("%d min. or (%2.02f Hrs)"), i , k); m_ctrl.InsertString(count++, str); i= i+30; } i hope u got the problm ,, that is i also need answer in shape of 1.00 , 1.50 , 2.00 , 2.50 etc. but its shows 1.50 , 2,50 ..as 1.00 , 2.00 respectvly. measn it round .50 to lower .00 value thanx

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Hi ! Instead of using k= i/60; use k= i/60.00; When both operand of a division are integer, the result will be automatically an integer (even if this is not a round number). When one operand is float, the result will be a float also.

      Z 1 Reply Last reply
      0
      • C Cedric Moonen

        Hi ! Instead of using k= i/60; use k= i/60.00; When both operand of a division are integer, the result will be automatically an integer (even if this is not a round number). When one operand is float, the result will be a float also.

        Z Offline
        Z Offline
        Zeeshan Bilal
        wrote on last edited by
        #3

        thanks .. it works..

        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