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. Double getlength

Double getlength

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 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.
  • D Offline
    D Offline
    Davitor
    wrote on last edited by
    #1

    Hi All Can i get double length?I have a variable double l=111.98987744,so can i get

    l length

    Plz help me.

    C 1 Reply Last reply
    0
    • D Davitor

      Hi All Can i get double length?I have a variable double l=111.98987744,so can i get

      l length

      Plz help me.

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

      You mean the size in bytes of a double ? If yes, use the sizeof operator: int lenght = sizeof(double);

      Cédric Moonen Software developer
      Charting control [v2.0] OpenGL game tutorial in C++

      D 1 Reply Last reply
      0
      • C Cedric Moonen

        You mean the size in bytes of a double ? If yes, use the sizeof operator: int lenght = sizeof(double);

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

        D Offline
        D Offline
        Davitor
        wrote on last edited by
        #3

        Thanks for reply. i use your code.It's return always 8.

        double tr=111.989877445678;
        int lenght = sizeof(tr);
        result is length=8;

        C 1 Reply Last reply
        0
        • D Davitor

          Thanks for reply. i use your code.It's return always 8.

          double tr=111.989877445678;
          int lenght = sizeof(tr);
          result is length=8;

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

          Yes, that's the size of a double. Errr.. wait, you make me wonder. Are you asking for the lenght of the string representing the double ? If yes, there's no way to know that with precision because of the floating point precision. For instance, if you store 1 in a double, its value won't be exactly 1, but maybe 1.00000000001. So, it's not what you expect. Anyway, why do you want know something like that ? It doesn't make a lot of sense... If you want to convert your double to a string, you can always specify the precision you want to keep.

          Cédric Moonen Software developer
          Charting control [v2.0] OpenGL game tutorial in C++

          D 1 Reply Last reply
          0
          • C Cedric Moonen

            Yes, that's the size of a double. Errr.. wait, you make me wonder. Are you asking for the lenght of the string representing the double ? If yes, there's no way to know that with precision because of the floating point precision. For instance, if you store 1 in a double, its value won't be exactly 1, but maybe 1.00000000001. So, it's not what you expect. Anyway, why do you want know something like that ? It doesn't make a lot of sense... If you want to convert your double to a string, you can always specify the precision you want to keep.

            Cédric Moonen Software developer
            Charting control [v2.0] OpenGL game tutorial in C++

            D Offline
            D Offline
            Davitor
            wrote on last edited by
            #5

            you can always specify the precision you want to keep

            yes i am converting double to Cstring(CSting str.formate("%.4f",double)). But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy. Any way there is any more option to convert double to CString. Plz help me

            C C 2 Replies Last reply
            0
            • D Davitor

              you can always specify the precision you want to keep

              yes i am converting double to Cstring(CSting str.formate("%.4f",double)). But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy. Any way there is any more option to convert double to CString. Plz help me

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

              Davitor wrote:

              But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy.

              Well, but that's what I was explaining: tr=98.29982355, in that specific case, it is very probable that your double will be stored with some imprecision (for instance tr=98.299823499999999). There's no way for the computer to guess which precision you want to keep, that's up to you to tell to the computer where the number should be rounded when converting to string. I suggest you read this article[^] about floating point precision.

              Cédric Moonen Software developer
              Charting control [v2.0] OpenGL game tutorial in C++

              1 Reply Last reply
              0
              • D Davitor

                you can always specify the precision you want to keep

                yes i am converting double to Cstring(CSting str.formate("%.4f",double)). But i want to convert same values like if double tr=98.29982355 then i want to convert Cstring str=98.29982355 and when tr=9.89 then str=9.89. So i think if i have a length of double then it's make to easy. Any way there is any more option to convert double to CString. Plz help me

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                Why don't you use str.Format("%f", d) then? :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                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