1number.toLocaleString("en-US", {
2 minimumIntegerDigits: 2,
3 useGrouping: false,
4});
1var numarr = [8, 32, 128]
2var formatted = []
3//create three numbers of different lengths
4numarr.forEach(num => {
5 formatted.push(
6 num.toLocaleString('en-US', {//this is the function that formats the numbers
7 minimumIntegerDigits: 2, //change this to your minimum length
8 useGrouping: false
9 })
10 )
11})
12//after running this, formatted == [08, 32, 128]
1[7, 27.5, -7.2345].forEach(myNumber => {
2 let formattedNumber = myNumber.toLocaleString('en-US', {
3 minimumIntegerDigits: 2,
4 useGrouping: false
5 })
6 console.log(
7 'Input: ' + myNumber + '\n' +
8 'Output: ' + formattedNumber
9 )
10})