js format string 2 digits code example
Example 1: javascript format number 2 digits
var numarr = [8, 32, 128]
var formatted = []
numarr.forEach(num => {
formatted.push(
num.toLocaleString('en-US', {
minimumIntegerDigits: 2,
useGrouping: false
})
)
})
Example 2: js format string 2 digits
[7, 27.5, -7.2345].forEach(myNumber => {
let formattedNumber = myNumber.toLocaleString('en-US', {
minimumIntegerDigits: 2,
useGrouping: false
})
console.log(
'Input: ' + myNumber + '\n' +
'Output: ' + formattedNumber
)
})