By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

Convert double to and from string alwasy using '.' as separator?

P: n/a
Hi!

In germany, norway and France(?) we are using ',' as decimal separator
and it always messes up when you convert a double to and from a string
where the interface expects double values stored as string is using '.'

What parameter shall I use in double.ToString() to ensure that the
outputstring always are using '.' as separator without thousand sep,
and what parameter shall I use to convert double to Double.Parse() or
Convert.ToDouble() to ensure that '.' is expected.

Opposite: How do I parse the string "3,14" to return 3.14 independent of
current locale if trying to parse it as "3.14" fails?

--
Bjorn Brox
Mar 31 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Use the invariant culture - i.e.

decimal foo = 12345.6M;
// change the locale to demo
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("fr-FR");
// this line is locale dependent
string oops = foo.ToString();
// these 2 lines are locale independent
string bar = foo.ToString(CultureInfo.InvariantCulture);
decimal foo2 = decimal.Parse(bar, CultureInfo.InvariantCulture);

Marc
Mar 31 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.