动作脚本串号 [英] Action Script string to number

查看:134
本文介绍了动作脚本串号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的语句问题

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.

这篇关于动作脚本串号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆