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. How to round of Decimal Number ?

How to round of Decimal Number ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 4 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.
  • A Offline
    A Offline
    Arul Joseph
    wrote on last edited by
    #1

    If the number is 24.58. How to round of it as 25? If the number is 24.34 How to round of as 24.

    H B S 3 Replies Last reply
    0
    • A Arul Joseph

      If the number is 24.58. How to round of it as 25? If the number is 24.34 How to round of as 24.

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See here[^]


      WhiteSky


      1 Reply Last reply
      0
      • A Arul Joseph

        If the number is 24.58. How to round of it as 25? If the number is 24.34 How to round of as 24.

        B Offline
        B Offline
        beko
        wrote on last edited by
        #3

        Hello, double round(double Num, double Seed) { double fac = Num / Seed; fac = (fac < 0) ? (ceil(fac - 0.5)) : (floor(fac + 0.5)); // fac = (fac < 0) ? static_cast(fac-0.5) : static_cast(fac+0.5); return fac * Seed; } round(3.7856, 0.001); = 3.786 Hope this helps. Bekir

        1 Reply Last reply
        0
        • A Arul Joseph

          If the number is 24.58. How to round of it as 25? If the number is 24.34 How to round of as 24.

          S Offline
          S Offline
          Sumesh V V
          wrote on last edited by
          #4

          Try this method int nRoundFigure; nRoundFigure = (int)( 24.58 + 0.5 ); // Answer will be 25 nRoundFigure = (int)( 24.34 + 0.5 ); // Answer will be 24 Hope this will work:)

          Known is a drop, unknown is an ocean

          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