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 get most significant digit ?

How to get most significant digit ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 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.
  • C Offline
    C Offline
    Cedric Moonen
    wrote on last edited by
    #1

    Hi ! I need to retrieve the most significant digit of a number. This must also be rounded to the inferior 'unit'. Example: I have 5238.12 and I must have 1000.00 I have 0.02578 and I must have 0.01000 I have 5.45 and I must have 1.00 Any idea ? Thanks

    C P 2 Replies Last reply
    0
    • C Cedric Moonen

      Hi ! I need to retrieve the most significant digit of a number. This must also be rounded to the inferior 'unit'. Example: I have 5238.12 and I must have 1000.00 I have 0.02578 and I must have 0.01000 I have 5.45 and I must have 1.00 Any idea ? Thanks

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

      Ok I've found a solution: I can calculate the log10 of the number. I round the solution to integer value. This integer value will give me the number of zero of the number for 5238.12 the log10 is 3.7192. So I know I have 3 zeros... :-D Negative numbers will give me the floating point position.

      P 1 Reply Last reply
      0
      • C Cedric Moonen

        Hi ! I need to retrieve the most significant digit of a number. This must also be rounded to the inferior 'unit'. Example: I have 5238.12 and I must have 1000.00 I have 0.02578 and I must have 0.01000 I have 5.45 and I must have 1.00 Any idea ? Thanks

        P Offline
        P Offline
        Pedro Ruiz
        wrote on last edited by
        #3

        Try this code: d=pow(10,(int)floor(log10(f))); f=input, d=output.

        C 1 Reply Last reply
        0
        • C Cedric Moonen

          Ok I've found a solution: I can calculate the log10 of the number. I round the solution to integer value. This integer value will give me the number of zero of the number for 5238.12 the log10 is 3.7192. So I know I have 3 zeros... :-D Negative numbers will give me the floating point position.

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          Cool!!!


          MSN Messenger. prakashnadar@msn.com Tip of the day of visual C++ IDE. "We use it before you do! Visual C++ was developed using Visual C++"

          1 Reply Last reply
          0
          • P Pedro Ruiz

            Try this code: d=pow(10,(int)floor(log10(f))); f=input, d=output.

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

            Great :-) ! I found the same solution as you at the same time :-D (but your explanation is simpler that mine ;P ) Thanks

            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