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 ={Value} label="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; } }
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;
}
}
how to convert number to text
ReplyDelete