"함수 is number()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
10번째 줄: 10번째 줄:
==C#==
==C#==
[[category: Csharp]]
[[category: Csharp]]
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
private bool is_number(string str)
private bool is_number(string str)
{
{
16번째 줄: 16번째 줄:
   return double.TryParse(str, out num);
   return double.TryParse(str, out num);
}
}
</source>
</syntaxhighlight>


==Excel==
==Excel==
[[category: Excel]]
[[category: Excel]]
<source lang='php'>
<syntaxhighlight lang='php'>
// TRUE
// TRUE
=ISNUMBER(1)
=ISNUMBER(1)
27번째 줄: 27번째 줄:
=ISNUMBER("1")
=ISNUMBER("1")
=ISNUMBER("A")
=ISNUMBER("A")
</source>
</syntaxhighlight>


==Java==
==Java==
{{참고|자바 isNumeric()}}
{{참고|자바 isNumeric()}}
[[분류: Java]]
[[분류: Java]]
<source lang='java'>
<syntaxhighlight lang='java'>
public static boolean isNumeric(String input) {
public static boolean isNumeric(String input) {
   try {
   try {
50번째 줄: 50번째 줄:
// false
// false
System.out.println( isNumeric("A") );
System.out.println( isNumeric("A") );
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
function is_numeric(obj) {
function is_numeric(obj) {
   if(obj === '')return false;
   if(obj === '')return false;
61번째 줄: 61번째 줄:
   return true;
   return true;
}
}
</source>
</syntaxhighlight>


==Objective-C==
==Objective-C==
[[category: Objective-C]]
[[category: Objective-C]]
<source lang='objc'>
<syntaxhighlight lang='objc'>
#define IS_NUMERIC(x) [[NSScanner scannerWithString:x] scanFloat:NULL]
#define IS_NUMERIC(x) [[NSScanner scannerWithString:x] scanFloat:NULL]
// 1 (YES)
// 1 (YES)
74번째 줄: 74번째 줄:
// 0 (NO)
// 0 (NO)
NSLog(@"%d", IS_NUMERIC(@"Hello"));
NSLog(@"%d", IS_NUMERIC(@"Hello"));
</source>
</syntaxhighlight>


==PHP==
==PHP==
{{참고|PHP is_numeric()}}
{{참고|PHP is_numeric()}}
[[category: PHP]]
[[category: PHP]]
<source lang='php'>
<syntaxhighlight lang='php'>
// true
// true
is_numeric(42);  
is_numeric(42);  
88번째 줄: 88번째 줄:
// false
// false
is_numeric("A");
is_numeric("A");
</source>
</syntaxhighlight>


==Perl==
==Perl==
[[category: Perl]]
[[category: Perl]]
<source lang='perl'>
<syntaxhighlight lang='perl'>
if ($string =~ m/^(\d+\.?\d*|\.\d+)$/){
if ($string =~ m/^(\d+\.?\d*|\.\d+)$/){
print "The string matches valid number";
print "The string matches valid number";
}
}
</source>
</syntaxhighlight>


==VB==
==VB==
[[category: VB]]
[[category: VB]]
<source lang='VB'>
<syntaxhighlight lang='VB'>
' True
' True
IsNumeric(123)
IsNumeric(123)
110번째 줄: 110번째 줄:
IsNumeric("Hello")
IsNumeric("Hello")
IsNumeric("Hello123")
IsNumeric("Hello123")
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:36 기준 최신판

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 }}