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. The difference between . and ,

The difference between . and ,

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

    Hi I'm reading data from a file with a double stored in it. What I want to do is cast the double from a string to a double. The thing is that string looks like this "37.05" instead of this "37,05". Now what I want to know is if it is ok to just exchange the . for a , or would this cause a FormatException on some other system?

    C F 2 Replies Last reply
    0
    • J johanhertz

      Hi I'm reading data from a file with a double stored in it. What I want to do is cast the double from a string to a double. The thing is that string looks like this "37.05" instead of this "37,05". Now what I want to know is if it is ok to just exchange the . for a , or would this cause a FormatException on some other system?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      The method Convert.ToDouble()[^] can take a string and optionally an object that implements the IFormatProvider interface. This means you can tell the converter the format the information is in. The example at the bottom of the page I linked to gives an example of creating a format provider in order to convert the string successfully into a double. Does this help?


      My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      1 Reply Last reply
      0
      • J johanhertz

        Hi I'm reading data from a file with a double stored in it. What I want to do is cast the double from a string to a double. The thing is that string looks like this "37.05" instead of this "37,05". Now what I want to know is if it is ok to just exchange the . for a , or would this cause a FormatException on some other system?

        F Offline
        F Offline
        FriendlyFiend
        wrote on last edited by
        #3

        The best way is to provide a IFormatProvider from the culture in which your App is running this makes sure you have international support. Eg, Double.Parse(N, Thread.CurrentCulture.NumberFormat); A short term fix is to pass a number style argument to Double.Parse, with the current decimal seperator in your case "," in some other countries ".", look up MSDN for details on numberstyles, basic format is [ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

        J 1 Reply Last reply
        0
        • F FriendlyFiend

          The best way is to provide a IFormatProvider from the culture in which your App is running this makes sure you have international support. Eg, Double.Parse(N, Thread.CurrentCulture.NumberFormat); A short term fix is to pass a number style argument to Double.Parse, with the current decimal seperator in your case "," in some other countries ".", look up MSDN for details on numberstyles, basic format is [ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

          J Offline
          J Offline
          johanhertz
          wrote on last edited by
          #4

          Thank you I will try that.

          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