473,657 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ToDoubl e(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 2182
replace , with a .

ie strInput = "123.8"

and you could also use double.Parse(st rInput)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Marty" <re***@to.forum > wrote in message
news:ycIZc.8717 9$X12.24242@edt nps84...
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.ToDoubl e(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.Globaliz ation.CultureIn fo.CurrentUICul ture.NumberForm at.CurrencyDeci m
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.ToDoubl e(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.Globaliz ation.CultureIn fo.CurrentUICul ture.NumberForm at.CurrencyDeci m
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.ToDoubl e(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.ToDoubl e(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(Syst em.Globalizatio n.CultureInfo.I nvariantCulture )
MsgBox(s)
d = Double.Parse(s, System.Globaliz ation.CultureIn fo.InvariantCul ture)
MsgBox(d.ToStri ng())
///

--
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.ToDoubl e(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(Syst em.Globalizatio n.CultureInfo.I nvariantCulture )
MsgBox(s)
d = Double.Parse(s, System.Globaliz ation.CultureIn fo.InvariantCul ture)
MsgBox(d.ToStri ng())
///

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
47063
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
2
4957
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 'System.OverflowException' occurred in mscorlib.dll Additional information: Value was either too large or too small for a Double. Pascal
2
11506
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 will only need to handle numbers that increment by1/32. That is 1/32, 2/32, 3/32.... 31/32, 1. If the doublenumber is 0.28 which is between 1/4 and 9/32, the string shouldbe 9/32(go with the bigger number). TIA --------------------------------...
0
8403
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", System.Globalization.NumberSty­les.Currency));
17
4361
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 problem writing VB Double values to the file so as the Pascal program can read them as Pascal Real values. I've managed to find the algorithm to read the Pascal Real format and convert it to a VB Double, but I cannot figure out the opposite...
2
6619
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 doubleVal = System.Convert.ToDouble(stringVal) Msgbox (doubleVal) will return 101.01 but...... Dim stringVal As String = "101.00"
6
1407
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 declaration statments (first lines) e.g. Public Function ConvertCurrencyToEnglish(ByVal MyNumber As Double) As String Private Function ConvertHundreds(ByVal MyNumber As String) As String etc.
4
4514
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 it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
15
7648
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 pass it as a double value to the method format() which is shown below. when i do Double.parseDouble i get dTot as 5.037717235E7 CurrencyConverter.format(Double.parseDouble(FreemarkerTools.formatDecimal(dTot)));
1
4048
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 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...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.