I have a string format: 3,500,000 VNĐ
How can I use jquery to split it to 3500000.
I just know how to split it split("VNĐ")
after that the result is 3,500,000 ,
?
I have a string format: 3,500,000 VNĐ
How can I use jquery to split it to 3500000.
I just know how to split it split("VNĐ")
after that the result is 3,500,000 ,
?
您可以尝试像这样的正则表达式
var x = '3,500,000 VNĐ'.replace(/[,\s(VNĐ)]/g, '')
如果你希望 x 是一个 int 值,那么
var x = parseInt('3,500,000 VNĐ'.replace(/[,\s(VNĐ)]/g, ''), 10)
由于数字和字符串之间有空格,您可以这样做:
var str = "3,500,000 VNĐ";
var n = str.split(" "); //split by space
Comma(,)
然后再次使用拆分功能删除:
var number = n[0].replace(/\,/g,""); //remove comma