valid number formats ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam

    #1

    valid number formats ?

    Hi,
    How can I check if a string corresponds to a valid number format ?
    e.g :
    1,000.00
    1.000,00
    1 000,00
    1'000.00

    How to check the above are valid number formats ?

    Regards

  • Jonathan Allen

    #2
    Re: valid number formats ?

    Dim x as Double
    If Double.TryParse ("1,000.00", Any, CultureInfo.Inv ariantCulture, x) Then
    'it was parsed and x contains the result
    Else
    'it failed
    End If

    --
    Jonathan Allen


    "Sam" <samuel.berthel ot@voila.fr> wrote in message
    news:1117640417 .702223.11170@g 44g2000cwa.goog legroups.com...[color=blue]
    > Hi,
    > How can I check if a string corresponds to a valid number format ?
    > e.g :
    > 1,000.00
    > 1.000,00
    > 1 000,00
    > 1'000.00
    >
    > How to check the above are valid number formats ?
    >
    > Regards
    >[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: valid number formats ?

      "Sam" <samuel.berthel ot@voila.fr> schrieb:[color=blue]
      > How can I check if a string corresponds to a valid number format ?
      > e.g :
      > 1,000.00
      > 1.000,00
      > 1 000,00
      > 1'000.00
      >
      > How to check the above are valid number formats ?[/color]

      The samples you are giving are concreate instances of certain number
      formats. You can use 'Double.TryPars e' to check if the string can be parsed
      and interpreted as a number.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Sam

        #4
        Re: valid number formats ?

        Hi,
        Thx for your replies. I've tried Jonathan's code:

        Dim x As Double
        If Double.TryParse (row("Formattin g").ToString ,
        NumberStyles.An y, CultureInfo.Inv ariantCulture, x) Then
        .....

        I don't understand why with 1.000,00 it returns false
        and with 1,000.00 it returns true. Is 1,000.00 a valid format? I would
        have thought it was.....

        Comment

        • Cor Ligthert

          #5
          Re: valid number formats ?

          Sam,
          [color=blue]
          > I don't understand why with 1.000,00 it returns false
          > and with 1,000.00 it returns true. Is 1,000.00 a valid format? I would
          > have thought it was.....
          >[/color]

          Do you live in France or are you only using a French email address?

          Cor



          Comment

          • Sam

            #6
            Re: valid number formats ?

            Cor,
            Why this question ? I'm French but I live in London.
            1,000.00 and 1.000,00 to me are both valid but maybe 1.000,00 isn't
            valid in the UK ?

            Sam

            Comment

            • Cor Ligthert

              #7
              Re: valid number formats ?

              Sam,

              Because it is set in a computer, you use either the English language
              notation of numbers
              1,000.00 or as the other European languages 1.000,00. Your computer sees
              that from the settings.

              Cor


              Comment

              • Sam

                #8
                Re: valid number formats ?

                Ok, then I can't rely on TryParse, because someone based in the UK or
                in the USA could have a machine with European settings, which would
                prevent him having a english format.... argh :( this is so annoying!

                Comment

                • Cor Ligthert

                  #9
                  Re: valid number formats ?

                  Sam,

                  I really am curious how you solve this.

                  When I type this, than what is the value in your opinion.

                  1,500

                  This has nothing to do with programming.

                  A man cannot be a woman (at the same time).

                  Cor


                  Comment

                  • Sam

                    #10
                    Re: valid number formats ?

                    hehe...
                    I've got a table in my database that has a few fields amongst which, a
                    Number Format (1,000.00 or 1,000 or whatever), and a Decimal character
                    (, or . or whatever) so I know what is the decimal part.
                    1,500 if my Decimal character is , then it means this number is one and
                    and a half, otherwise it means it is one thousand and five hundred.
                    I know it 's a arse...

                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: valid number formats ?

                      "Sam" <samuel.berthel ot@voila.fr> schrieb:[color=blue]
                      > 1,000.00 and 1.000,00 to me are both valid but maybe 1.000,00 isn't
                      > valid in the UK ?[/color]

                      I don't think that 1.000,00 is valid in the UK, but it's valid in Germany
                      and Austria.

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://classicvb.org/petition/>

                      Comment

                      • Sam

                        #12
                        Re: valid number formats ?

                        No it was a mistake in my sentence. 1.000,00 is not valid in the UK and
                        1,000.00 is valid.

                        Comment

                        • Herfried K. Wagner [MVP]

                          #13
                          Re: valid number formats ?

                          "Sam" <samuel.berthel ot@voila.fr> schrieb:[color=blue]
                          > No it was a mistake in my sentence. 1.000,00 is not valid in the UK and
                          > 1,000.00 is valid.[/color]

                          ACK.

                          --
                          M S Herfried K. Wagner
                          M V P <URL:http://dotnet.mvps.org/>
                          V B <URL:http://classicvb.org/petition/>

                          Comment

                          Working...