format currency regular expression javascript

时间:2015-06-15 14:45:47

标签: javascript regex

I need to display a formatted number on a web page using JavaScript. I want to format it so that there are commas in the right places. How would I do this with a regular expression? I've gotten as far as something like this:

I am trying to use regular expression using JavaScript to format currency for both in English and in French. Based on my language it should use a particular regular expression. The English is working well but am trying to figure out the French.

return "$" + num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');

This is working for English. So my 5000 get converted to $5,000.00 this is fine.

I need French to looks like this 5 000,00 $

1 个答案:

答案 0 :(得分:1)

return num = num.substring(1).replace(/,/g , " ").replace(".", ",") + " $";

Use this to English formatted num.

相关问题