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?
If you want to add percentage sign to a number without multiplying the number by 100, such as to change 6 into 6% in Excel with Percentage Style, you should have the general number divided by 100 first, and then apply the Percentage Style to the numbers for displaying them as percentage 6% in Excel.
On the Home tab, in the Number group, click the icon next to Number to display the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Percentage. In the Decimal places box, enter the number of decimal places that you want to display.
You can run npm install numeral and then import the numeral package in whatever component you want to use it in. npm install numeralimport numeral from 'numeral'; Now that you're referencing the library, we can start using it!
js. A javascript library for formatting and manipulating numbers. Website and documentation.
For anyone still looking for the easiest way of achieving this, there is a numeral option you can set like so:
numeral.options.scalePercentBy100 = false;
Credit to Csaba Toth for creating the PR. PR Here
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
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With