Talk:Determine if a string is numeric: Difference between revisions
Content added Content deleted
Line 23: | Line 23: | ||
: And what is its input? The Python and C samples take a string. The Ruby and Scheme samples take an object. And in Tcl it's the same thing. |
: And what is its input? The Python and C samples take a string. The Ruby and Scheme samples take an object. And in Tcl it's the same thing. |
||
:Half the samples shown implement 'is integer', or 'is numeric character'. |
|||
:In VB, IsNumeric is a function for validating input. VB examples (all true) |
|||
:: 1, 1.1, -1.1, "1", "1.1", "-1.1" "1.1-", " 1.1- ", " 1,1 ", " 1E1" "&HFF" |
|||
:VBscript: |
|||
:::msgbox isnumeric(1) |
|||
:::msgbox isnumeric(1.1) |
|||
:::msgbox isnumeric(-1.1) |
|||
:::msgbox isnumeric("1") |
|||
:::msgbox isnumeric( "1.1") |
|||
:::msgbox isnumeric( "-1.1") |
|||
:::msgbox isnumeric( " 1.1- ") |
|||
:::msgbox isnumeric(" 1,1 ") |
|||
:::msgbox isnumeric(" 1E1 ") |
|||
:::msgbox isnumeric(" &HFF ") |
Revision as of 03:54, 20 September 2007
Unix shell
#!/bin/sh a='123' if [ "$a" -eq "$a" ] 2>/dev/null then echo "a is numeric" else echo "a is abnumeric" fi
Exact definition of IsNumeric?
For those who don't know VB: How exactly is IsNumeric defined? For example: Is leading/trailing whitespace allowed (i.e. " 123" or "123 ")? Does it also accept floting point values (e.g. "2.5" or "1e5")? What about thousands separators (e.g. "10,000")? Is that locale-dependent? Are numbers in other bases (e.g. hexadecimal) allowed (assuming VB supports them otherwise)? What about numbers too big to fit into a native integer (e.g. "9999999999999999999999999999999999999999999999999") resp. a native float (e.g. "1e1234567")?
- And what is its input? The Python and C samples take a string. The Ruby and Scheme samples take an object. And in Tcl it's the same thing.
- Half the samples shown implement 'is integer', or 'is numeric character'.
- In VB, IsNumeric is a function for validating input. VB examples (all true)
- 1, 1.1, -1.1, "1", "1.1", "-1.1" "1.1-", " 1.1- ", " 1,1 ", " 1E1" "&HFF"
- VBscript:
- msgbox isnumeric(1)
- msgbox isnumeric(1.1)
- msgbox isnumeric(-1.1)
- msgbox isnumeric("1")
- msgbox isnumeric( "1.1")
- msgbox isnumeric( "-1.1")
- msgbox isnumeric( " 1.1- ")
- msgbox isnumeric(" 1,1 ")
- msgbox isnumeric(" 1E1 ")
- msgbox isnumeric(" &HFF ")