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. Float to CString problem

Float to CString problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 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.
  • R Offline
    R Offline
    raju_shiva
    wrote on last edited by
    #1

    Hi sir, I am finding the pow of some values,If it is for smaller values,i am getting the result properly. But if for larger values like (where result will be like2.20700e+007) I am using this code:

    result = pow(temp1,temp3);

    res.Format("%2d",result);

    result is in float and i am getting value as 2.20700e+007 then i am trying to convert it into CString,so that i can tokenize the result in this way(2.20700) But i am getting junk values while converting,its not converting properly. Am i doing any thing wrong or any other way to convert it to CString,where i can get the value properly Thanks Raj

    C N A 3 Replies Last reply
    0
    • R raju_shiva

      Hi sir, I am finding the pow of some values,If it is for smaller values,i am getting the result properly. But if for larger values like (where result will be like2.20700e+007) I am using this code:

      result = pow(temp1,temp3);

      res.Format("%2d",result);

      result is in float and i am getting value as 2.20700e+007 then i am trying to convert it into CString,so that i can tokenize the result in this way(2.20700) But i am getting junk values while converting,its not converting properly. Am i doing any thing wrong or any other way to convert it to CString,where i can get the value properly Thanks Raj

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #2

      as you said, you are going to operate on larger values, the problem should be that, your resultant value is exceeding the 4 byte boundary, and you are getting improper result. by the way, what are the values you are passing to pow? what is the result you are getting, and what is the result you are expecting?

      -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

      R 1 Reply Last reply
      0
      • C chandu004

        as you said, you are going to operate on larger values, the problem should be that, your resultant value is exceeding the 4 byte boundary, and you are getting improper result. by the way, what are the values you are passing to pow? what is the result you are getting, and what is the result you are expecting?

        -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

        R Offline
        R Offline
        raju_shiva
        wrote on last edited by
        #3

        chandu004 wrote:

        what are the values you are passing to pow?

        The value varies,depends on some condition. ex: pow(0.2365,-0.3445)....

        chandu004 wrote:

        what is the result you are getting

        result = pow(temp1,temp3); // Here i a am getting the result as 2.20700e+007

        chandu004 wrote:

        what is the result you are expecting?

        I am expecting the same result in CString res.Format("%2d",result); // here i am getting some junk values in res. I hope i cleared u Thanks Raj

        C 1 Reply Last reply
        0
        • R raju_shiva

          Hi sir, I am finding the pow of some values,If it is for smaller values,i am getting the result properly. But if for larger values like (where result will be like2.20700e+007) I am using this code:

          result = pow(temp1,temp3);

          res.Format("%2d",result);

          result is in float and i am getting value as 2.20700e+007 then i am trying to convert it into CString,so that i can tokenize the result in this way(2.20700) But i am getting junk values while converting,its not converting properly. Am i doing any thing wrong or any other way to convert it to CString,where i can get the value properly Thanks Raj

          N Offline
          N Offline
          Niklas L
          wrote on last edited by
          #4

          :omg: If result is a float you should use %f instead of %d.

          home

          1 Reply Last reply
          0
          • R raju_shiva

            chandu004 wrote:

            what are the values you are passing to pow?

            The value varies,depends on some condition. ex: pow(0.2365,-0.3445)....

            chandu004 wrote:

            what is the result you are getting

            result = pow(temp1,temp3); // Here i a am getting the result as 2.20700e+007

            chandu004 wrote:

            what is the result you are expecting?

            I am expecting the same result in CString res.Format("%2d",result); // here i am getting some junk values in res. I hope i cleared u Thanks Raj

            C Offline
            C Offline
            chandu004
            wrote on last edited by
            #5

            look at the following url. http://www.elook.org/programming/c/pow.html[^] there he says that, There's a domain error if base is zero and exp is less than or equal to zero i think you may have to do some workaround on this.

            -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

            1 Reply Last reply
            0
            • R raju_shiva

              Hi sir, I am finding the pow of some values,If it is for smaller values,i am getting the result properly. But if for larger values like (where result will be like2.20700e+007) I am using this code:

              result = pow(temp1,temp3);

              res.Format("%2d",result);

              result is in float and i am getting value as 2.20700e+007 then i am trying to convert it into CString,so that i can tokenize the result in this way(2.20700) But i am getting junk values while converting,its not converting properly. Am i doing any thing wrong or any other way to convert it to CString,where i can get the value properly Thanks Raj

              A Offline
              A Offline
              Aescleal
              wrote on last edited by
              #6

              You're trying to format a float with a decimal (i.e integer) format specifier. Use %f instead. Ash PS: Ooops, that'll teach me to leave a respsonse unsent while I go to a meeting.

              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