473,324 Members | 2,248 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,324 software developers and data experts.

Convert to double problem

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 problem ?

Yoav.
Sep 26 '07 #1
4 2531
On Sep 26, 10:37 am, "Yoavo" <y...@cimatron.co.ilwrote:
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 problem ?
Chances are you're using a culture which doesn't use "." as the
decimal separator.

Try specifying CultureInfo.InvariantCulture as the culture in the
Convert.ToDouble call.

Jon

Sep 26 '07 #2
Yoavo wrote:
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 problem ?

Yoav.
The ToDouble method is using a NumberFormat object that specifies
different characters for decimal separator and thousands separator than
what you have in the string.

The method uses the NumberFormat of the CultureInfo.CurrentCulture object.

You can use the Double.Parse method instead, so that you can specify the
FormatInfo or CultureInfo object directly. For a string that uses a
period as decimal separator, you can use the InvariantCulture object:

string s = "2.1415926536";
double d = double.Parse(s, CultureInfo.InvariantCulture);

--
Göran Andersson
_____
http://www.guffa.com
Sep 26 '07 #3
I found what was the problem.
I was using "," as decimal point instad of "."
Isn't this function should work OK if I am using "," as decimal point ??
"Yoavo" <yo**@cimatron.co.ilwrote in message
news:eI*************@TK2MSFTNGP03.phx.gbl...
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 problem ?

Yoav.


Sep 30 '07 #4
Yoavo wrote:
I found what was the problem.
I was using "," as decimal point instad of "."
Isn't this function should work OK if I am using "," as decimal point ??
It works just fine if you specify a FormatInfo or CultureInfo that
correctly describes how you write the number. Example:

string s = "3,1415926536";
CultureInfo swedish = new CultureInfo(1053);
double d = double.Parse(s, swedish);

--
Göran Andersson
_____
http://www.guffa.com
Sep 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: photomonkey | last post by:
I am having a problem with a relatively simple sql query, and was hoping that somebody could help me on this forum. Basicaly the situation is that I have two tables, a Vendors table (Vendors)...
9
by: FalkoG | last post by:
Hello colleague I want to convert a floating number for example 5236.9856982 to a hexadecimal number. I'd tried several things but my problem is to convert the position after decimal point. I...
0
by: R. John Reed | last post by:
Hi All, I'm am looking to convert a currency string (e.g. "$1,234.56" to a double value). It appears this will work: double val = Convert.ToDouble(Double.Parse­("$123,456.78901",...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
3
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title,...
3
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be...
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...
4
by: ashishbhatt12 | last post by:
Hi all, i have a problem in the value which stored in memory location.i want to convert it into the double value. Suppose, i have the value int k = 2; when I write it on the memory...
1
by: y2ktan | last post by:
Hi Ladies and Gentlements, I have a variable with the type of double. Let said that it is 0.003. double dblValue = 0.003 Now, when I want to convert it to string with the local regional...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.