SpreadJS 14
Features / Cells / Cell Format / Percentage Format
In This Topic
    Percentage Format
    In This Topic

    Users can easily and efficiently work with numbers and percentage in Spreadsheets. SpreadJS provides support to automatically append the percentage '%' symbol at the end of the input (digits 0-9) for the cells that have the percentage format applied to them.

     Cell with a percentage format

    SpreadJS applies different functionalities for different inputs while appending percentage symbol as elaborated below:  

    Case 1: Entering a number

    If you enter a number in a percentage-formatted cell, then SpreadJS adds the % symbol to it. For example, the entering a value 6 in the cell formats it to 6.00%.

    Case 2: Entering a character

    If you enter a character, symbol or letter in the percentage-formatted cell, SpreadJS does not append the % symbol to it.

    Case 3: Adding a character after a digit

    If you add a letter (such as 'h') after a number (such as '6') in the percentage-formatted cell, then SpreadJS will still append the percentage symbol (formatted as 6h%).

    Case 4: Deleting percentage symbol in cell-edit mode

    If you enter a number in the cell-edit mode and remove the % symbol from the number and exit the cell, then the number is again converted to the percentage format.

    Case 5: Inserting number with % symbol in non-formatted cell

    If you do not set the percentage format in a cell and directly type a number with the "%" symbol, like "11%", then the percentage format is set automatically.

    Case 6: Double-clicking a cell and inserting number

    If a percentage-formatted cell is double clicked and a number is inserted in the cell-edit mode, the number is converted to the percentage format first and the % symbol is added to it. That is, if we double-click the cell and add 45, it formats to 4500.00%.

    Case 7: Adding + or - symbols with numbers

    You can add + or – symbols before the number in a percentage-formatted cell. For example, +2 becomes 2.00% and -5 becomes -5.00%.

    Using Code

    This example depicts the use of percentage formatting in Spreadsheet cells.

    JavaScript
    Copy Code
    // For Range A1:F10, set formatter
    for (var i = 0; i < 10; i++)
        for (var j = 0; j < 6; j++)
            activeSheet.getCell(i, j).formatter("0.00%");