A Flash Developer Resource Site

Results 1 to 20 of 41

Thread: Math.round() - Currency and date issues for mortgage app.

Hybrid View

  1. #1
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Good morning

    Here's some sample code for working out a payment schedule.

    code:

    // Utility function to determine if leap year
    isLeapYear = function(year)
    {
    return ( year % 4 == 0 &&
    (year % 100 != 0 || year % 400 == 0) );

    }

    // Utility function to determine number of days in month
    // (including leap years)
    kmDays = [31, 28, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31];
    getMonthDays = function(year,mNbr) // month is from 0 - 11
    {
    return kmDays[mNbr] + (mNbr == 1 && isLeapYear(year));
    }

    // Sample Usage
    // print end of month for next 52 pay periods

    var dat = new Date();
    yr = dat.getFullYear(); // get current year
    mn = dat.getMonth(); // get current month (0-11)

    // loop over number of pay periods
    for (var i = 0; i < 52; ++i)
    {
    var dat = new Date(yr,mn,getMonthDays(yr,mn));
    var datString = dat.getFullYear() + '.' + (dat.getMonth()+1) + '.' + dat.getDate();

    trace(i + ": " + datString);

    // increment month - if we reach end o f year, reset month and increment year
    if (++mn >= 12) {
    mn = 0;
    yr++;
    }
    }


    Last edited by jbum; 06-11-2004 at 02:04 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center