Friday, October 8, 2021

Convert number to Indian format value in LWC JS salesforce

This post explains how to convert any number to indian format number in LWC Javascript salesforce.


The indian format of 1423443 is 14,23,443.
Note: Method toLocaleString() is applied on decimal and float values. So if your number is in string format then parse your value before using this method.

NumberFormat.cmp :


<template>
    <div style="background-color:wheat; padding:20px;">
        <lightning-input type="Number" onchange ={Valuelabel="Enter Text"></lightning-input>
        <br/>
        <lightning-button type="submit"
            name="Convert Number"
            label="Convert Number"
            onclick={FormatNumber}>
        </lightning-button>
        <br/>
        <div>
            Indian format of given number is: {formatNum}
        </div>
    </div>
</template>

NumberFormat.js :


import { LightningElement,track } from 'lwc';
export default class NumberFormat extends LightningElement {
        @track Number;
        @track formatNum;

        Value(event){
            this.Number = event.target.value;
            console.log(this.Number);
        }
        FormatNumber(event){
            var indian = parseFloat(this.Number).toLocaleString('en-IN');
            this.formatNum = indian;
        }
    
}

Output :


Convert number to Indian format


Thanks, 
Lovesalesforceyes


1 comment:

Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...