var money = prompt("Enter an amount of money");
money = parseFloat(money);
var months = prompt("Enter how long you will be investing for in months");
months = parseInt(months);
months = Math.round(months);
var interest = prompt("Enter an interest rate you would like to test your investment at");
interest = parseFloat(interest);
console.log(months);
爲什麼這段代碼無論什麼時候都要捨去幾個月?我有什麼不同的做法?爲什麼這段代碼沒有正確舍入數字
因爲你,當你說'parseInt函數(月)截斷月'? – cHao
重複,有很多關於此問題的答案:http://stackoverflow.com/questions/7342957/how-do-you-round-to-1-decimal-place-in-javascript/7343013#7343013 – jcollum
RTFM - https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt。 「parseInt將數字截斷爲整數值。」 – j08691