Convert a string in decimal
Hello, I have xml file with a number format that I have problems. because the number is coded .5 instead of 0.5, and even worse -. 5 instead -0.5. I know I can make the conversion to the simplest.
Example, if string starts with '.' Or '-.' Then ....
But as I have millions to import data in this format I am looking for your efficient suggestions.
What do you think?
Thank you in advance for your ideas.
Re: Convert a string in decimal
If you want to convert to a decimal format (types float, double, decimal).
Code:
using System. Globalization;
...
chiffre1 string = ".5";
chiffre2 string = "-. 5";
CultureInfo ci = new CultureInfo ( "en-US");
double1 double = double. Parse (chiffre1, ci);
double2 double = double. Parse (chiffre2, ci);
Re: Convert a string in decimal
hi
would rather see in your regional options, you can display entire option as zero, you must put it on the correct format.
Fast, simple and accurate ...
This may help you.
Re: Convert a string in decimal
change the setting of the position to make a simple deserialization is a bit too much, especially when there is a solution as simple as that proposed by the other people on this forum ...
Moreover, the numerical values in the text document are encoded in a standard format. So rather than go through the U.S. culture, especially through the invariant culture.
Thus
Code:
CultureInfo ci = CultureInfo. InvariantCulture;