함수 is_number()

Is Number
Is Numeric
IsNumber
is_numeric
IsNumeric

1 C#[ | ]

private bool is_number(string str)
{
  double num;
  return double.TryParse(str, out num);
}

2 Excel[ | ]

// TRUE
=ISNUMBER(1)

// FALSE
=ISNUMBER("1")
=ISNUMBER("A")

3 Java[ | ]

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[ | ]

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[ | ]

#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[ | ]

// true
is_numeric(42); 
is_numeric("42");
is_numeric(3.14159);
is_numeric("1e5");

// false
is_numeric("A");

7 Perl[ | ]

if ($string =~ m/^(\d+\.?\d*|\.\d+)$/){
	print "The string matches valid number";
}

8 VB[ | ]

' True
IsNumeric(123)
IsNumeric("123")
IsNumeric("42")
IsNumeric("3.14159")

' False
IsNumeric("Hello")
IsNumeric("Hello123")

9 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}