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#
  4. ToDouble problem

ToDouble problem

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • J Offline
    J Offline
    Jose Vicente
    wrote on last edited by
    #1

    Hello. I'm using the ToDouble function from the System.Convert namespace to convert from a String to Double. I have problems using it. With a String that has the value of '56.3' I'm getting as a result a double like this 56.2999999993. I have tried to use the ToDouble Method of the String object and I get the same result. What I'm doing wrong ??:confused:

    H J 2 Replies Last reply
    0
    • J Jose Vicente

      Hello. I'm using the ToDouble function from the System.Convert namespace to convert from a String to Double. I have problems using it. With a String that has the value of '56.3' I'm getting as a result a double like this 56.2999999993. I have tried to use the ToDouble Method of the String object and I get the same result. What I'm doing wrong ??:confused:

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      What happens when you try Double.Parse("56.3")?

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      J 1 Reply Last reply
      0
      • H Heath Stewart

        What happens when you try Double.Parse("56.3")?

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        J Offline
        J Offline
        Jose Vicente
        wrote on last edited by
        #3

        The same thing

        J S 2 Replies Last reply
        0
        • J Jose Vicente

          The same thing

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Well, you can always make it work with another call Math.Round(double.Parse("3.2"), 3); The graveyards are filled with indispensible men.

          1 Reply Last reply
          0
          • J Jose Vicente

            The same thing

            S Offline
            S Offline
            sammyh
            wrote on last edited by
            #5

            A double is a double precision floating point number. Floating point numbers can't always represent a number perfectly. If you need better accuracy, there is the Decimal data type (But it is VERY slow compared to double) Beginning of this article talks a bit about it http://tom.cs.byu.edu/~557/text/ch14.pdf

            1 Reply Last reply
            0
            • J Jose Vicente

              Hello. I'm using the ToDouble function from the System.Convert namespace to convert from a String to Double. I have problems using it. With a String that has the value of '56.3' I'm getting as a result a double like this 56.2999999993. I have tried to use the ToDouble Method of the String object and I get the same result. What I'm doing wrong ??:confused:

              J Offline
              J Offline
              Jose Vicente
              wrote on last edited by
              #6

              :)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