- Is Number
- Is Numeric
- IsNumber
- is_numeric
- IsNumeric
1 C#[ | ]
C#
Copy
private bool is_number(string str)
{
double num;
return double.TryParse(str, out num);
}
2 Excel[ | ]
PHP
Copy
// TRUE
=ISNUMBER(1)
// FALSE
=ISNUMBER("1")
=ISNUMBER("A")
3 Java[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
Java
Copy
public static boolean isNumeric(String input) {
try {
Double.parseDouble(input);
return true;
}
catch (NumberFormatException e) {
return false;
}
}
...
//true
System.out.println( isNumeric("42") );
System.out.println( isNumeric("3.14") );
System.out.println( isNumeric("1e5") );
// false
System.out.println( isNumeric("A") );
4 JavaScript[ | ]
JavaScript
Copy
function is_numeric(obj) {
if(obj === '')return false;
if(isNaN(obj))return false;
if(typeof(obj) !== 'number' && typeof(obj) !== 'string')return false;
return true;
}
5 Objective-C[ | ]
Objective-C
Copy
#define IS_NUMERIC(x) [[NSScanner scannerWithString:x] scanFloat:NULL]
// 1 (YES)
NSLog(@"%d", IS_NUMERIC(@"42"));
NSLog(@"%d", IS_NUMERIC(@"-3.14159"));
NSLog(@"%d", IS_NUMERIC(@"1e5"));
// 0 (NO)
NSLog(@"%d", IS_NUMERIC(@"Hello"));
6 PHP[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
PHP
Copy
// true
is_numeric(42);
is_numeric("42");
is_numeric(3.14159);
is_numeric("1e5");
// false
is_numeric("A");
7 Perl[ | ]
Perl
Copy
if ($string =~ m/^(\d+\.?\d*|\.\d+)$/){
print "The string matches valid number";
}
8 VB[ | ]
vbnet
Copy
' True
IsNumeric(123)
IsNumeric("123")
IsNumeric("42")
IsNumeric("3.14159")
' False
IsNumeric("Hello")
IsNumeric("Hello123")
9 같이 보기[ | ]
편집자 Jmnote Ykhwong Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.