Forum Replies Created

  • Nick Hamilton

    November 26, 2015 at 12:07 pm in reply to: Technique for Animated Number Countdown with Commas

    And if you would like to count over 1,000,000 and keep the comma’s in:

    startCount = 0;
    endCount = 48000000;
    countDur = 3;

    var num = Math.round(linear(time,0,countDur,startCount,endCount))
    num = Comma(num);
    [num]

    function Comma(number)
    {
    number = ” + Math.round(number);
    if (number.length > 3)
    {
    var mod = number.length % 3;
    var output = (mod > 0 ? (number.substring(0,mod)) : ”);
    for (i=0 ; i < Math.floor(number.length / 3); i++)
    {
    if ((mod == 0) && (i == 0))
    output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
    else
    output+= ‘,’ + number.substring(mod + 3 * i, mod + 3 * i + 3);
    }
    return (output);
    }
    else return number;
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy