Tuesday, 28 September 2021

How to display formatted value in LWC component ?

1. Hide all numbers and display only 4 digits of SSN or credit card.

Declare a variable in Java Script controller that is being used in LWC component.

<lightning-formatted-number value={ssn}></lightning-formatted-number> 

 In the java script controller 

var num = '123456789234'; // you are getting SSN from apex class

ssn = num.slice(-4).padStart(num.length,'*');

Console.log('ssn',ssn);



2. Append . to the end of string.

var charString = 'Learning Salesforce';

charString.padEnd(30,'.');


3. Append Currency Symbol 

var testNum = 123445.34;

testNum.toLocaleString('en-IN',{style:"currency",currency:'INR'});

testNum.toLocaleString('en-US', { style: 'currency',currency:'USD'})

testNum.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' })

testNum.toLocaleString('en-GB', { style: 'currency', currency: 'EUR' })


4. Display percentage value

var testNum = 0.2;

testNum.toLocaleString('en-US', { style: 'percent'})





No comments: