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. Precision in C

Precision in C

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 5 Posters 1 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
    Anonygeeker
    wrote on last edited by
    #1

    Hi, I have a value float a=1234.5578 I want to print output as 1234.55. How to approach this ?

    P R L D 4 Replies Last reply
    0
    • A Anonygeeker

      Hi, I have a value float a=1234.5578 I want to print output as 1234.55. How to approach this ?

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Read up on printf formatting. Google will find you lots of tutorials and references.

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      1 Reply Last reply
      0
      • A Anonygeeker

        Hi, I have a value float a=1234.5578 I want to print output as 1234.55. How to approach this ?

        R Offline
        R Offline
        Rick York
        wrote on last edited by
        #3

        Are you sure you want 1234.55 as output? The number would be rounded to 1234.56.

        1 Reply Last reply
        0
        • A Anonygeeker

          Hi, I have a value float a=1234.5578 I want to print output as 1234.55. How to approach this ?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Unless you are going to be programming large scale complex mathematical problems you should stay well clear of floating point numbers. There are quite a few issues to be understood which can catch you out. And given this and the question below, your time would be better spent getting hold of a good C++ study guide. Trying to learn by posting questions here will take you far too much time.

          1 Reply Last reply
          0
          • A Anonygeeker

            Hi, I have a value float a=1234.5578 I want to print output as 1234.55. How to approach this ?

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Try here.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            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