如何在 JavaScript 中将带有零的字符串转换为数字?

javascriptweb developmentfront end technologyobject oriented programming更新于 2026/1/6 15:08:17

假设以下是我们的字符串”

var stringValue="453.000.00.00.0000";

要将上述带有零的字符串转换为数字,请使用 parseInt() 和 replace() −

var numberValue = parseInt(stringValue.replace(/\./gm, ''));

示例

以下是完整代码 −

var stringValue="453.000.00.00.0000";
var numberValue = parseInt(stringValue.replace(/\./gm, ''));
console.log("Original value="+stringValue)
console.log("After modification the value="+numberValue);

要运行上述程序,请使用以下命令 −

node fileName.js.

这里,文件名是 demo239.js。

输出

输出如下 −

PS C:\Users\Amit\javascript-code> node demo239.js
Original value=453.000.00.00.0000
After modification the value=45300000000000

相关文章


有用资源