[英]How to convert a string with zeros to number in javascript?
I have this string: "140.000.000"
, when I try to convert it to number with parseInt
or parseFloat
, it always give me 140
without the rest, I already tried with replacing the "."
我有这个字符串:
"140.000.000"
,当我尝试使用parseInt
或parseFloat
将其转换为数字时,它总是给我140
而没有 rest,我已经尝试过替换"."
with ","
, but it does not work, someone can help me?用
","
,但它不起作用,有人可以帮助我吗?
"140.000.000"
isn't a valid Number, neither "140,000,000"
. "140.000.000"
不是有效数字, "140,000,000"
也不是。 Run the code below,运行下面的代码,
console.log(isNaN("140.000.000")) console.log(isNaN("140,000,000")) console.log(isNaN("140000000"))
However, "140000000"
is.但是,
"140000000"
是。 So, try replacing the .
所以,尝试更换
.
with empty string as,用空字符串作为,
str = "140.000.000" n = Number(str.replace(/\./g, '')) console.log(n)
const str ="140.000.000" console.log(parseInt(str.split('.').join('')))
Remove the dots:删除点:
const num = parseInt(`140.000.000`.replace(/\./gm, '')); console.log(num)
Try the following尝试以下
const string = "140.000.000"; const number = parseInt(string.replace(/\./g,"")); console.log(number);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.