Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  32] [ 7]  / answers: 1 / hits: 26152  / 11 Years ago, wed, july 10, 2013, 12:00:00

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

More From » jquery

 Answers
182

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

[#77098] Monday, July 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mitchellg

Total Points: 235
Total Questions: 117
Total Answers: 106

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
mitchellg questions
Sun, Jan 10, 21, 00:00, 3 Years ago
Fri, Aug 21, 20, 00:00, 4 Years ago
Fri, Jul 10, 20, 00:00, 4 Years ago
;