so what i mean is:
1000 should become 10,00
10000 should become 100,00
100000 should become 1000,00
Can some help me out?
CodePudding user response:
var number = 1000;
// request a currency format
console.log(number.toLocaleString('en-US', { style: 'currency', currency: 'USD' }));
Without methods and just formatting with commas
function addComma(value) {
return value.split('').map((v, i) => {
if ( i === value.length - 2) {
return ',' v
}
return v
}).join('')
}
console.log(addComma('1000'))
console.log(addComma('10000'))
console.log(addComma('100000'))