How do I get from var x:number = 1200 to x = 1.200 or var x: number = 8 to x = 8.0 ?
CodePudding user response:
Method toFixed will help you.
x = 1200
x = x.toFixed(1) // 1200.0
CodePudding user response:
actually, don't know what you want :
const conv = (num) => {
arr = [...('' num)] ;
arr.splice(1, 0, '.')
if (arr[arr.length-1] == '.') arr.push('0') ;
return arr.join('')
}
console.log( conv(1200), conv(8) ) // 1.200 8.0