International Number Formatting

  • Thread starter Thread starter Steve Peterson
  • Start date Start date
S

Steve Peterson

Hi

I have an app where I have to deal with both Spanish & American formatting.
I have a string that represents a number that I need to convert to Int32
before I enter it in the database. The string can be any number, for
example, "1,355" (American style) or "1.355" (Spanish style) . I know could
use the Replace method and "strip" the number string of "." or the "," then
convert what is left to Int32.

But I thought maybe there is a better way using the CultureInfo class that
simply converts any culture number sting to a number. However, I'm having
problems figuring this one out.

Can anyone lend a helping hand?

TIA

Steve
 
Hi,

Dim strEng As String = "1,355"
Dim strSpanish As String = "1.355"

Dim intEng As Integer = Integer.Parse(strEng,
Globalization.NumberStyles.AllowThousands, New
System.Globalization.CultureInfo("en-US"))

Dim intSpanish As Integer = Integer.Parse(strSpanish,
Globalization.NumberStyles.AllowThousands, New
System.Globalization.CultureInfo("es-ES"))

Trace.WriteLine(String.Format("{0} = {1}", strEng, intEng))
Trace.WriteLine(String.Format("{0} = {1}", strSpanish, intSpanish))


Ken
 
Thanks Ken

That did the trick!

Steve


Ken Tucker said:
Hi,

Dim strEng As String = "1,355"
Dim strSpanish As String = "1.355"

Dim intEng As Integer = Integer.Parse(strEng,
Globalization.NumberStyles.AllowThousands, New
System.Globalization.CultureInfo("en-US"))

Dim intSpanish As Integer = Integer.Parse(strSpanish,
Globalization.NumberStyles.AllowThousands, New
System.Globalization.CultureInfo("es-ES"))

Trace.WriteLine(String.Format("{0} = {1}", strEng, intEng))
Trace.WriteLine(String.Format("{0} = {1}", strSpanish, intSpanish))


Ken
 
Back
Top