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

Convert from double to string

Hi,

If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:

1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to double
to have this output : 123.8

Thanks a lot!

Marty
Jul 21 '05 #1
6 2153
replace , with a .

ie strInput = "123.8"

and you could also use double.Parse(strInput)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Marty" <re***@to.forum> wrote in message
news:ycIZc.87179$X12.24242@edtnps84...
Hi,

If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:

1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to double to
have this output : 123.8

Thanks a lot!

Marty

Jul 21 '05 #2
Marty,

Maybe you can use this,

If
System.Globalization.CultureInfo.CurrentUICulture. NumberFormat.CurrencyDecim
alSeparator = "," Then
I hope this helps?

Cor
If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:

1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to double
to have this output : 123.8

Thanks a lot!

Marty

Jul 21 '05 #3
This is exactly what I was looking for,

Thanks a lot!

Cor Ligthert wrote:
Marty,

Maybe you can use this,

If
System.Globalization.CultureInfo.CurrentUICulture. NumberFormat.CurrencyDecim
alSeparator = "," Then
I hope this helps?

Cor

If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:

1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to double
to have this output : 123.8

Thanks a lot!

Marty


Jul 21 '05 #4
* Marty <re***@to.forum> scripsit:
If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:
1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to
double to have this output : 123.8


I suggest to store the values formatted in the invariant culture (this
culture uses "." instead of ",") and then parse the number using this
culture:

\\\
Dim d As Double = 22.34234
Dim s As String = d.ToString(System.Globalization.CultureInfo.Invari antCulture)
MsgBox(s)
d = Double.Parse(s, System.Globalization.CultureInfo.InvariantCulture)
MsgBox(d.ToString())
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jul 21 '05 #5
Does it mean that if the user write in the textbox "123,8", this
invariant culture could replace the "," by a "." ?

Marty
Herfried K. Wagner [MVP] wrote:
* Marty <re***@to.forum> scripsit:
If I don't know that my (or any) windows 2k regional setting for the
decimal symbol is the dot (".") and I want to do this:
1- Dim dblOutput As Double
2- Dim strInput As String
3- strInput = "123,8"
4- dblOutput = Convert.ToDouble(strInput)

How can I avoid an error at line four ? And get it converted to
double to have this output : 123.8

I suggest to store the values formatted in the invariant culture (this
culture uses "." instead of ",") and then parse the number using this
culture:

\\\
Dim d As Double = 22.34234
Dim s As String = d.ToString(System.Globalization.CultureInfo.Invari antCulture)
MsgBox(s)
d = Double.Parse(s, System.Globalization.CultureInfo.InvariantCulture)
MsgBox(d.ToString())
///

Jul 21 '05 #6
* Marty <re***@to.forum> scripsit:
Does it mean that if the user write in the textbox "123,8", this
invariant culture could replace the "," by a "." ?


No. I was referring to values that are stored in a file, for example.
If the user types in "12,123", on an en-US system 'Double.Parse' will
return 12,123.0 whereas on an de-DE system it would return 12.123.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jul 21 '05 #7

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

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
2
by: Pascal | last post by:
Why does this not work, and how should i do this convert in stead: string x = double.MinValue.ToString(); double y = Convert.ToDouble(x); i get this exception: An unhandled exception of type...
2
by: paul gao via .NET 247 | last post by:
hi all. In my program I need to convert a double number to stringrepresentation in fraction format and vise versa. For example,convert 0.75 to string "3/4" and convert string "1/2" to 0.5.The class...
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...
2
by: Jason | last post by:
In VB.NET, when I use System.Convert.ToDouble(string Val) to convert a string variable to double variable, I got something interesting: Dim stringVal As String = "101.01" Dim doubleVal As Double...
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
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...
15
by: shiniskumar | last post by:
How to convert string to double? Ive got a double variable dTot; its value is 5.037717235E7 when i did FreemarkerTools.formatDecimal(dTot) i got it as string "50377172.35". now i want to...
1
by: Bjorn Brox | last post by:
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...
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...
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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.