numeric check

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

    #1

    numeric check

    Hi,

    I am looking for some function that tests if a value is numeric. I could not
    find a function for this.

    At the moment I am using "WHERE CONV(myfield,10 ,10)!=0" but I suppose there
    must be a better way.

    Thanks,
    Wim


  • Good Man

    #2
    Re: numeric check

    "Wim Roffil" <wimroffel@plea se_no_spam-planet.nl> wrote in
    news:cvki6g$pqs $1@reader13.wxs .nl:
    [color=blue]
    > Hi,
    >
    > I am looking for some function that tests if a value is numeric. I
    > could not find a function for this.[/color]

    you should do this in whatever scripting language you use. In php, you
    would use good ol' is_numeric();

    Finds whether a variable is a number or a numeric string





    Comment

    • Bill Karwin

      #3
      Re: numeric check

      Wim Roffil wrote:[color=blue]
      > I am looking for some function that tests if a value is numeric. I could not
      > find a function for this.
      >
      > At the moment I am using "WHERE CONV(myfield,10 ,10)!=0" but I suppose there
      > must be a better way.[/color]

      This is not a good method, because CONV("0", 10, 10) results in zero,
      despite "0" clearly being a numeric value. :-)

      The same thing happens if you try to use implicit casting:
      SELECT 'abc' + 0;

      You could try:
      myfield REGEXP '[[:digit:]]+'
      but that would only get positive integers.

      To include negative, fractional, and exponented numbers you could try:
      myfield REGEXP
      '[-+]?[[:digit:]]+(\.[[:digit:]]+)?(E[-+][[:digit:]]+)?'

      This is better than simply:
      myfield REGEXP '[-+0-9.]+'
      because the latter would identifies "...---000" as a valid number.

      Regards,
      Bill K.

      Comment

      • Wim Roffil

        #4
        Re: numeric check


        "Bill Karwin" <bill@karwin.co m> schreef in bericht
        news:cvld9201rr u@enews3.newsgu y.com...[color=blue]
        > Wim Roffil wrote:[color=green]
        > > I am looking for some function that tests if a value is numeric. I could[/color][/color]
        not[color=blue][color=green]
        > > find a function for this.
        > >
        > > At the moment I am using "WHERE CONV(myfield,10 ,10)!=0" but I suppose[/color][/color]
        there[color=blue][color=green]
        > > must be a better way.[/color]
        >
        > This is not a good method, because CONV("0", 10, 10) results in zero,
        > despite "0" clearly being a numeric value. :-)
        >
        > The same thing happens if you try to use implicit casting:
        > SELECT 'abc' + 0;
        >
        > You could try:
        > myfield REGEXP '[[:digit:]]+'
        > but that would only get positive integers.
        >
        > To include negative, fractional, and exponented numbers you could try:
        > myfield REGEXP
        > '[-+]?[[:digit:]]+(\.[[:digit:]]+)?(E[-+][[:digit:]]+)?'
        >
        > This is better than simply:
        > myfield REGEXP '[-+0-9.]+'
        > because the latter would identifies "...---000" as a valid number.
        >
        > Regards,
        > Bill K.[/color]

        Thanks Bill, that helps me.

        Wim


        Comment

        Working...