.NETGURU
Convert from double to string
Messages   Related Types
This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Marty
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
Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* Marty <Click here to reveal e-mail address> scripsit:
[Original message clipped]

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.InvariantCulture)
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/>
Reply to this message...
 
    
Marty
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:
[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* Marty <Click here to reveal e-mail address> scripsit:
[Original message clipped]

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/>
Reply to this message...
 
    
Cor Ligthert
Marty,

Maybe you can use this,

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

Cor

[Original message clipped]

Reply to this message...
 
    
Marty
This is exactly what I was looking for,

Thanks a lot!

Cor Ligthert wrote:

[Original message clipped]

Reply to this message...
 
    
Hermit Dave
replace , with a .

ie strInput = "123.8"

and you could also use double.Parse(strInput)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Marty" <Click here to reveal e-mail address> wrote in message
news:ycIZc.87179$X12.24242@edtnps84...
[Original message clipped]

Reply to this message...
 
 
System.Convert
System.Double
System.Globalization.CultureInfo




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification