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. simple type Conversion from string to double

simple type Conversion from string to double

Scheduled Pinned Locked Moved C#
5 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.
  • K Offline
    K Offline
    Krugger404
    wrote on last edited by
    #1

    Hi, I have a very simple, yet nagging problem. I am trying to convert some string containing numbers and dots to double. The thing is that double convert (Convert.ToDouble) crashes if the string to convert contains a dot (e.g. "10.10") Can you please help me around this problem. Thanks:confused: Krugger

    S S 2 Replies Last reply
    0
    • K Krugger404

      Hi, I have a very simple, yet nagging problem. I am trying to convert some string containing numbers and dots to double. The thing is that double convert (Convert.ToDouble) crashes if the string to convert contains a dot (e.g. "10.10") Can you please help me around this problem. Thanks:confused: Krugger

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      You're probably running the code on a machine where the standard culture of the OS and consequently of your application usually use another decimal separator (e.g. in german os the comma), so you have to use an overload that takes an IFormatProvider providing proper culture-specific formatting information.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      K 1 Reply Last reply
      0
      • K Krugger404

        Hi, I have a very simple, yet nagging problem. I am trying to convert some string containing numbers and dots to double. The thing is that double convert (Convert.ToDouble) crashes if the string to convert contains a dot (e.g. "10.10") Can you please help me around this problem. Thanks:confused: Krugger

        S Offline
        S Offline
        Sandeep Akhare
        wrote on last edited by
        #3

        Simple try this string str = "10.23"; double db; db=Double.Parse(str); i think it might help you :)

        Thanks and Regards Sandeep If you want something you never had, do something you have never done!

        1 Reply Last reply
        0
        • S Stefan Troschuetz

          You're probably running the code on a machine where the standard culture of the OS and consequently of your application usually use another decimal separator (e.g. in german os the comma), so you have to use an overload that takes an IFormatProvider providing proper culture-specific formatting information.


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          K Offline
          K Offline
          Krugger404
          wrote on last edited by
          #4

          Thank you. In fact, i just figured it out myself but thank you for the tip. It indeed has to do with the locale. :) Krugger

          G 1 Reply Last reply
          0
          • K Krugger404

            Thank you. In fact, i just figured it out myself but thank you for the tip. It indeed has to do with the locale. :) Krugger

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            You can use CultureInfo.InvariantCulture to easily get a number format where the decimal separator definitely is a period. string s = "3.1415926536"; double p = double.Parse(s, CultureInfo.InvariantCulture);

            --- single minded; short sighted; long gone;

            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