Fit.UI icon indicating copy to clipboard operation
Fit.UI copied to clipboard

Allow number formatting using thousand separator

Open Jemt opened this issue 7 years ago • 1 comments

We need to be able to format numbers with both decimal and thousand separators.

Jemt avatar Jun 07 '18 09:06 Jemt

Perhaps something like this.

function format(int)
{
    var negative = (int < 0);
    var val = Math.abs(int) + "";
    var skipLength = val.length % 3;
    var preVal = val.substring(0, skipLength);
    val = val.substring(skipLength);
    val = preVal + val.replace(/(\d{3})/g, ".$1");

    if (val.indexOf(".") === 0)
        val = val.substring(1);

    if (negative)
        val = "-" + val;

    return val;
}

Jemt avatar Jun 07 '18 09:06 Jemt