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 to string

double to string

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

    hi, i'm looking for a routine to convert double to string with at least a precision as the windows calculator does(32 digits after the comma)! does someone know such a function?? thx 4 help, IceMatrix

    L A 2 Replies Last reply
    0
    • I IceMatrix

      hi, i'm looking for a routine to convert double to string with at least a precision as the windows calculator does(32 digits after the comma)! does someone know such a function?? thx 4 help, IceMatrix

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

      try this:

      double dFoo = 41.1325934653849974801841984193481498319048193849
      char string[256];
      sprintf("%d.32", dFoo);

      regards

      M 1 Reply Last reply
      0
      • I IceMatrix

        hi, i'm looking for a routine to convert double to string with at least a precision as the windows calculator does(32 digits after the comma)! does someone know such a function?? thx 4 help, IceMatrix

        A Offline
        A Offline
        Anna Jayne Metcalfe
        wrote on last edited by
        #3

        Sorry to dissapoint you, but the double datatype only supports 15 digits of precision. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_langref_data_type_ranges.asp[^] for details. If you need more than that, you're going to have to roll your own. Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

        L I 2 Replies Last reply
        0
        • A Anna Jayne Metcalfe

          Sorry to dissapoint you, but the double datatype only supports 15 digits of precision. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_langref_data_type_ranges.asp[^] for details. If you need more than that, you're going to have to roll your own. Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

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

          Anna-Jayne Metcalfe wrote: If you need more than that, you're going to have to roll your own. I didn't think you smoked ;P The tigress is here :-D

          A 1 Reply Last reply
          0
          • L Lost User

            Anna-Jayne Metcalfe wrote: If you need more than that, you're going to have to roll your own. I didn't think you smoked ;P The tigress is here :-D

            A Offline
            A Offline
            Anna Jayne Metcalfe
            wrote on last edited by
            #5

            Only in the event of fire, fudge or extreme drunkeness. ;) Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

            1 Reply Last reply
            0
            • A Anna Jayne Metcalfe

              Sorry to dissapoint you, but the double datatype only supports 15 digits of precision. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_langref_data_type_ranges.asp[^] for details. If you need more than that, you're going to have to roll your own. Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

              I Offline
              I Offline
              IceMatrix
              wrote on last edited by
              #6

              but how does the windows calc do it? IceMatrix

              A 1 Reply Last reply
              0
              • I IceMatrix

                but how does the windows calc do it? IceMatrix

                A Offline
                A Offline
                Anna Jayne Metcalfe
                wrote on last edited by
                #7

                It probably uses a custom datatype or a third party library containing one. Do a search on the web and you should find something suited to your needs. It may not, however, be free. Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

                I 1 Reply Last reply
                0
                • A Anna Jayne Metcalfe

                  It probably uses a custom datatype or a third party library containing one. Do a search on the web and you should find something suited to your needs. It may not, however, be free. Anna :rose: Homepage | My life in tears "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work. Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

                  I Offline
                  I Offline
                  IceMatrix
                  wrote on last edited by
                  #8

                  float f; double d; f = 3.1415926535897932384626433832795f; d = 3.1415926535897932384626433832795; printf( "%.32f\n", f ); printf( "%.32lf\n", d ); Output: 3.14159274101257320000000000000000 3.14159265358979310000000000000000 double has to be more precise, but the function doesnt show it!

                  1 Reply Last reply
                  0
                  • L Lost User

                    try this:

                    double dFoo = 41.1325934653849974801841984193481498319048193849
                    char string[256];
                    sprintf("%d.32", dFoo);

                    regards

                    M Offline
                    M Offline
                    melwyn
                    wrote on last edited by
                    #9

                    small correction of last line sprintf(string,"%f", dFoo);

                    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