I want to convert my JavaScript number into a currency number, but with any currency symbol
Suppose this is my number:
var number = 43434;
The result should be like this:
43,434
And not this:
$43,434
Using one regex /(\d)(?=(\d{3})+(?!\d))/g
:
"1234255364".replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
"1,234,255,364"
To achieve this with an integer you can use +""
trick:
var number = 43434;
(number + "").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); // 43,434
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With