function numberWithSpaces(x) { return x.toString().replace(/B(?=(d{3})+(?!d))/g, " "); // 1650000 to 1 650 000 }