472,344 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

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

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
1 3841
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists....
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot....
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal...
6
by: Jay | last post by:
I need to convert from a string a double that is followed by a scaling character (k means *1e3, M=*1e6, etc) then apply the scaling character....
2
by: Nicolai.Schoenberg | last post by:
When i try it like you say, he ignores the dot. For example s = "12.45"; d = double.Parse(s); d will be 1245.0 :( pls help
4
by: Yoavo | last post by:
Hi, I want to convert a string to double. I use the function: "System.Convert.ToDouble". The problem is that if the string contains the character...
3
by: TonyJ | last post by:
Hello! If I have a string for example 45 .12 and I want to convert this to double without replacing the . with a , how is that done. //Tony
5
by: Praveen | last post by:
got a string a="2.3944864845405107E+18" how to convert this into a valid number. which method to use.. I was using Convert.ToInt64(a); which is...
9
by: AGP | last post by:
I've been scratching my head for weeks to understand why some code doesnt work for me. here is what i have: dim sVal as string = "13.2401516"...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.