我不断得到 $NaN 而不是数字。(代码从 . 开始line 155
。)如何获得数字输出而不是$NaN
. 是否有更好的方法来调试它以确定返回的确切内容?
function daysInMonth(y, m) {
var t = new Date(y, m, 0);
return t.getDate();
}
function daysLeftInQuater(d) {
d = d || new Date(); // If no date supplied, use today
var t = new Date(d); // Don't mess up supplied date if there was one
var daysLeft = 2 - (t.getMonth() % 3);
do {
daysLeft += daysInMonth(t.getFullYear(), t.getMonth() + 1) - t.getDate();
t.setMonth(t.getMonth() + 1);
t.setDate(1);
} while (t.getMonth() % 3)
return daysLeft;
}
function getQuarter(d) {
d = d || new Date();
var m = Math.floor(d.getMonth()/3) + 2;
return m > 4? m - 5 : m;
}
function hoa_letsgo(){
var amt_due = $("#user_ad").val();
var qma_val = $("#qma_select").val();
if (qma_val == 1){//Q
var cur_year = $("#year").val(); var cur_day = $("#day").val();
var cur_month = $("#month").val(); var now = new Date(cur_month, cur_day, cur_year);
var days_left = daysLeftInQuater(cur_month);
var ind_amt = amt_due / 4;
var day_amt = amt_due / 360;
var quarter = getQuarter(now);
var am_cred = ind_amt * quarter;
var final_cred = am_cred + (day_amt * days_left);
final_cred = final_cred - amt_due;
final_cred = final_cred.toFixed(2)
$("#credit").html("$" + addCommas(final_cred));
}