【题目】
Validate if a given string is numeric.
Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
【解析】判断一个字符串是否是数字类型,是返回true,否返回false。一看到这题我就想到了JS超级简单,JAVA的解法下次补上。。。
【代码】
var isNumber = function(s) {
if(s==" ")
return false;
var bool=Number(s);
if(bool==0)
return true;
else
return Boolean(bool);
};
本文介绍了一种简单的JavaScript方法来判断一个给定的字符串是否可以转换为有效的数值,包括整数、浮点数及科学计数法表示的数值。

446

被折叠的 条评论
为什么被折叠?



