473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 3979
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. Thank your for your insight. 1. Create 4 double...
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. This way i can assure the text is correct. However...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
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. Example: "-1.345k #comment" I know roughly how...
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 "." the program aborts. What might be the...
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 going to exception. thanks Praveen
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" dim x as double x = sVal debug.writeline ( x)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.