如何在JavaScript中将具有零的字符串转换为数字?
假设以下是我们的字符串”
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
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短