我想了解如何使用parseFloat將字符串轉換爲數字 - 通過這種方式根據用戶獎勵俱樂部點的變化。試圖瞭解如何使用parseFloat將字符串轉換爲數字
這裏是我到目前爲止已經編寫的代碼:
var ptsBalance = jQuery('.value.large.withCommas').text(); // get current RC points balance
var strParse = parseInt(ptsBalance, 10); // * Output should be current RC balance
alert(strParse); // alert Rewards Club Balance
var bonusPoints = 70000;
var totalPts = jQuery(strParse + bonusPoints); // sum total of Bonus and Current points
jQuery(strParse).appendTo('.currentPts');
jQuery(totalPts).appendTo('.totalPts'); // insert RC points balance after 'Current Points' text
顯然我沒有使用pareFloat,而是strParse,這是我的舍入字符串。也就是說,如何將字符串轉換爲可以是「10」,「100」,「1,000」,「10,000」等的數字?
這裏是我的小提琴鏈接:http://jsfiddle.net/bkmills1/60vdfykq/
仍在學習...
提前感謝!
如果你要做很多貨幣/數字解析使用庫可能是有益的。像這樣[一個](http://openexchangerates.github.io/accounting.js/)可能會有所幫助。 – Jack 2015-04-01 20:06:57