(how to) International Number Formatting
(Wednesday, November 24, 2004)
Found the following interesting discussion in the Newsgroups:
International Number Formatting by: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
| | | Reply: by:Ken Tucker [MVP]
| | | 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
| | | Reply: by:Steve Peterson
| | | Thanks Ken
That did the trick!
Steve
|
Posted by Xander Zelders

|
0 Comments:
Post a Comment
<< Home