Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How convert string from CultureInfo("hr-HR") to any type after that get result string
of number with CultureInfo("en-US"),without Replace("."c;"")

What I have tried:

Dim dblValue as Double
Dim strNumValue as String="1.234.567,89"
Dim strNumValue_enUS as string
dblValue = CDbl(strNumValue)' {"Conversion from string "" 1.234.567,89"" to type 'Double' is not valid."}
strNumValue_enUS=dblvalue.ToString("N","en-US")
Posted
Updated 14-Feb-21 3:38am
v2
Comments
Richard MacCutchan 14-Feb-21 9:21am    
Use Double.TryParse().

1 solution

I'd sugegst to use Double.Parse method[^].

Take a look at this code:

VB
Dim strNumValue As String="1.234.567,89"

Dim dv As Double = 0
Dim cIn As CultureInfo = New CultureInfo("Hr-hr")
Dim cOut As CultureInfo = New CultureInfo("En-us")

dv = Double.Parse(strNumValue, cIn)
strNumValue = dv.ToString(cOut)
Console.WriteLine(strNumValue)
'prints: 1234567.89
strNumValue = dv.ToString("###,000.00", cOut)
Console.WriteLine(strNumValue)
'prints: 1,234,567.89


You can also use: Double.TryParse Method[^]
 
Share this answer
 
v3
Comments
RickZeeland 14-Feb-21 9:41am    
5d :)
Maciej Los 14-Feb-21 9:45am    
Thank you, Rick :)
[no name] 14-Feb-21 10:02am    
My tiny 5. But to be honest I would put the hint to 'TryParse' in bold size 16 ;)
Maciej Los 14-Feb-21 11:09am    
:)Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900