Re: Non-locale-specific floating point numbers



Mike Schilling <mscottschilling@xxxxxxxxxxx> wrote:
I want to write some C# that converts between floating-point numbers and
strings in a non-locale-specific way. That is, I want decimal points always
to be ".", etc. The simple overloads of Double.ToString() and
Double.Parse() change their behavior depending on locale. I'm considering
creating a static en-us locale and passing it to the overloads of Parse and
ToString that take a locale, but is there a better way?

Instead of creating a static en-us, use CultureInfo.InvariantCulture.
Pass that to methods as appropriate.

Of course, you could always wrap that up in your own helper class if
you're doing it a lot.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Non-locale-specific floating point numbers
    ... Double.Parsechange their behavior depending on locale. ... creating a static en-us locale and passing it to the overloads of Parse ... Instead of creating a static en-us, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Non-locale-specific floating point numbers
    ... strings in a non-locale-specific way. ... Double.Parsechange their behavior depending on locale. ... creating a static en-us locale and passing it to the overloads of Parse ... Unless i'm mistaken a float is a float inependent of locale. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Non-locale-specific floating point numbers
    ... Mike Schilling wrote: ... strings in a non-locale-specific way. ... I'm considering creating a static en-us locale and passing it to the overloads of Parse and ToString that take a locale, but is there a better way? ...
    (microsoft.public.dotnet.languages.csharp)
  • Non-locale-specific floating point numbers
    ... I want to write some C# that converts between floating-point numbers and ... strings in a non-locale-specific way. ... The simple overloads of Double.ToStringand ... Double.Parsechange their behavior depending on locale. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Printing formatted numbers into text file
    ... To format the strings, you'd probably need one of the String.Format ... Look at System.IO (FileStream) for writing into a file: ...
    (microsoft.public.dotnet.languages.csharp)