const formatToCurrency = amount => {
return "$" + amount.toFixed(2).replace(/d(?=(d{3})+.)/g, "$&,");
};
formatToCurrency(12.34546); //"$12.35"
formatToCurrency(42345255.356); //"$42,345,255.36
number = 1
converted = number.toString().padStart(3, '0')
console.log(converted)
// Expected output
" 001 "
function numberWithSpaces(x) {
return x.toString().replace(/B(?=(d{3})+(?!d))/g, " ");
}
var x = parseFloat('9.656');
x.toFixed(0); // returns 10
x.toFixed(2); // returns 9.66
x.toFixed(4); // returns 9.6560
x.toFixed(6);
function m(n,d){x=(''+n).length,p=Math.pow,d=p(10,d)
x-=x%3
return Math.round(n*d/p(10,x))/d+" kMGTPE"[x/3]}