[]
        
(Showing Draft Content)

Percentage Format

Users can easily and efficiently work with numbers and percentages in worksheets. 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.




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

  1. Entering a number

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

  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.

  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%).

  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.

  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.

  6. Double-clicking a cell and inserting a 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%.

  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%.

The following code sample depicts the use of percentage formatting in worksheet cells.

// 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%");