Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo
(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



 
Previous Posts
    - how to initialize array of object with vb.net
    - How to Connect to mysql
    - How to populate a listbox
    - Decimal To Binary Function Does Not Work
    - How to Run a batch file by passing parameters with...
    - WTSAPI32 Dll entry point missing for WTSSendMessag...
    - winmm.dll
    - How to play sounds that don't exist.
    - How to Execute a method in one form from another
    - How to inherit an attribute with the class it appl...

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland