gwatts / jquery.sparkline

A plugin for the jQuery javascript library to generate small sparkline charts directly in the browser
http://omnipotent.net/jquery.sparkline/
1.24k stars 278 forks source link

Formatting of values in the range -100 to -999 show an extra comma #116

Open gmathijssen opened 10 years ago

gmathijssen commented 10 years ago

See http://jsfiddle.net/gmathijssen/PfzXg/731/

Hoover over -105 and you will see -,105 instead of -105 This can be fixed in the formatNumber() function

jkieley commented 8 years ago

+1

AvaelKross commented 8 years ago

Same issue for -123123, -123123123 and any negative 3n-digit numbers.

AvaelKross commented 8 years ago

Here is a fixed function:

formatNumber = function (num, prec, groupsize, groupsep, decsep) {
    var p, i;
    num = (prec === false ? parseFloat(num).toString() : num.toFixed(prec)).split('');
    p = (p = $.inArray('.', num)) < 0 ? num.length : p;
    if (p < num.length) {
        num[p] = decsep;
    }
    shift = num[0] == '-' ? 1 : 0;
    for (i = p - groupsize; i > shift; i -= groupsize) {
        num.splice(i, 0, groupsep);
    }
    return num.join('');
};