开发者

Converting formatted string to integer in Javascript

开发者 https://www.devze.com 2023-01-29 09:12 出处:网络
how can i conve开发者_JAVA技巧rt \"570.581,88\" into an integer and sort accordingly?var s = \"570.581,88\";

how can i conve开发者_JAVA技巧rt "570.581,88" into an integer and sort accordingly?


var s = "570.581,88";

// Format as American input
s = s.replace(/\./g,'').replace(',','.');

// Integer
var i = parseInt(s,10);

// Floats
var f1 = parseFloat(s);
var f2 = s*1;
var f3 = +s;
0

精彩评论

暂无评论...
验证码 换一张
取 消