Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 JS 上有变量qty,类型是字符串。怎么改成integer or float?
qty
integer or float
在 PHP 中我们有 settype,用 JS 尝试同样的方法。它不起作用。
var qtyInt = parseInt(qty); var qtyFloat = parseFloat(qty);
将字符串转换为浮点数: var myFloat = parseFloat('77.3'); // 77.3
将字符串转换为整数: var myInt = parseInt('14'); // 14