Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com