3
I have a problem because I have a variable of the type string
and I need to convert to the guy double
without losing the "dot". Example: string latitude = "-8.709006"
when converting is equal to: -8.709006
But so far I’ve done several different tests and nothing.
string latitude = "-8.709006";
double lat = Double.Parse(latitude);
//Mas ele esta me trazendo: -8709006 e nao -8.709006
I’ve done it another way, too, but I don’t get it:
string latitude = "-8.709006";
System.Globalization.CultureInfo cult = new System.Globalization.CultureInfo("en-US");
double lat = double.Parse(latitude, cult);
//Desta vez o resultado foi: -8,709006 e nao -8.709006
As I tried too:
string latitude = "-8.709006";
double lat = Double.Parse(latitude, System.Globalization.CultureInfo.InvariantCulture);
//E o resultado foi: -8,709006 e nao -8.709006
I have also tried using Cultureinfo for "en-BR" and nothing: System.Globalization.Cultureinfo cult = new System.Globalization.Cultureinfo("en");
– Joaquim Caetano Teixeira
It worked for me https://dotnetfiddle.net/NMFJe4 I think your problem is not in the conversion but in the presentation.
– Maniero
I agree with @bigown, the problem seems to be in the presentation and not in the conversion itself.
– Richard Dias
@bigown aceibei de da da uma Ctrl+C in your code and the result remains the same here for min: -8,709006 really no longer what is happening!
– Joaquim Caetano Teixeira
@Joaquimcaetanoteixeira Already checked the time zone and language settings in the Control Panel?
– mutlei
@Joaquimcaetanoteixeira The type
double
stored in memory, has nothing to do with string representation using,
or.
. When you will check the value after doing the conversion, what is shown to you is the representation in string form, using the language configuration of your operating system.– Miguel Angelo
@Joaquimcaetanoteixeira Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? Need something to be improved?
– Maniero