由网友(她又失约了)分享简介:我有下面的语句问题trace(Number("1/2")) //output NaN但trace(Number("1.2")) //output 1.2所以,我有点困惑,为什么第一个语句不给出正确的结果?So, I am bit confused as why the first statement doesn'...
我有下面的语句问题
trace(Number("1/2")) //output NaN
但
trace(Number("1.2")) //output 1.2
所以,我有点困惑,为什么第一个语句不给出正确的结果?
So, I am bit confused as why the first statement doesn't gives correct result?
推荐答案
这可能预计的值是一个数字已经,不是计算。尝试解析这个字符串:1 + 2
。这将很可能导致NaN的为好。
It probably expects the value to be a number already, not a calculation. Try to parse this string: "1+2"
. It'll most likely result in NaN as well.
编辑:我已经运行测试
Number("1.2") = 1.2
Number("1+2") = NaN
Number("1/2") = NaN
因此,正如我说的,号()
构造函数使用数量,而不是计算。
So, as I said, the Number()
constructor expects a number, not a calculation.
相关推荐
最新文章