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. round off function in vc.net

round off function in vc.net

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++helptutorialquestion
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.
  • S Offline
    S Offline
    salaikumar
    wrote on last edited by
    #1

    hello How to use round funcion in vc++.net ...?? I need to round off a float value, say 103.94568 to 103.95 Please help.... Salai

    T J 2 Replies Last reply
    0
    • S salaikumar

      hello How to use round funcion in vc++.net ...?? I need to round off a float value, say 103.94568 to 103.95 Please help.... Salai

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      this is only a display issue...

      printf("%.2f", 103.94568);

      103.95


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      1 Reply Last reply
      0
      • S salaikumar

        hello How to use round funcion in vc++.net ...?? I need to round off a float value, say 103.94568 to 103.95 Please help.... Salai

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

        salaikumar wrote:

        I need to round off a float value, say 103.94568 to 103.95

        What is wrong with the old-fashioned way: adding .5 and casting to int (that is throwing the decimals away)? In your case you would additionally need to multiply by 100 before and divide by 100 afterwards to get the 2 decimal places.


        "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