Search code examples
formattinghandsontable

Format NumeralJS percentages without multiplying by 100


In Handsontable, you can use the format option on a numeric cell to format the values accordingly. Since it uses NumeralJS, I looked through the documentation to see how to format a number to just add the % sign and not multiply by 100 but can't find how to do this without setting my own.

Example cell:

{
    "type": "numeric",
    "format": "0.00%"
}

When the value is 7, it displays "700.00%". I'd like it to show `"7.00%". Any way of doing this in handsontable?


Solution

  • I do not think there is a way to do this currently without making changes to the numeral.js file.

    If you want, you can edit function formatPercentage (found in numberal.js) by removing the * 100 part:

    function formatPercentage (n, format, roundingFunction) {
        var space = '',
            output,
            value = n._value/* * 100*/; // comment out or remove * 100 here
    
        ...
    }