function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
balram kamboj 10balram kamboj 10 

Number-to-Percent In Lightning Datatable

I have a Increment__c custom field with data type number(15, 0) and it has a values of 2

I am trying to fetch and display the value 2 in standard datatable under "Increment" column.
 
{ label: 'Increment', fieldName: 'Increment__c', type: 'percent', cellAttributes: {alignment: 'center'}}

But my datatable showing value as 200% instead of 2%, which is multiplying the value with 100.

If i give type: 'number' in JS my datatable playground is displaying correct value like 2 but i want to display the % symbol for each value in the "Increment" column like 2%.

Please give me suggestions to achieve this.

Thanks
B
mukesh guptamukesh gupta
Hi Balram,

Displaying Currency and Percentages:-

Currency type displays a value based on the org currency and your Salesforce locale by default.
To override the default currency code, pass in a custom currencyCode value.
 
var columns = [
        { label: 'Amount', fieldName: 'amount', type: 'currency', typeAttributes: { currencyCode: 'EUR' }},
    // other column data
    ];

To specify the granularity on a currency or percentage for inline editing, pass in the step attribute. For example, specify step: 0.01 to allow numbers with two decimal places, or step: 0.001 permits three decimal places. Specify step: 1 to require whole numbers. The default is 0.01. You can preserve the number of fraction digits for display using minimumFractionDigits and maximumFractionDigits.
 
var columns = [
        { 
            label: 'Confidence', fieldName: 'confidence', type: 'percent',
            typeAttributes: { 
                step: '0.00001', minimumFractionDigits: '2', maximumFractionDigits: '3'
            },
            editable: true
        },
    // other column data
    ];

For example, if you pass in confidence: 0.21234 in your column data, the display value is 21.234%. When you inline edit, the step value is used to determine if your input is valid. If you pass in confidence: 0.78, the display value is 78.00% because minimumFractionDigits is set to 2.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
mhittmhitt
I am having the same issue, but my field data type is percent.  Using 'percent' type displays 5,500% instead of 55%, and text type shows the value, but I can't seem to add the % symbol manually. The proposed solution above doesn't change the value at all.