The difference between . and ,
-
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?
-
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?
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
-
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?
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]
-
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]
Thank you I will try that.