0

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 $

2

1 Answer 1

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

Use this to English formatted num.

Sign up to request clarification or add additional context in comments.

1 Comment

the substring is not working i used num.toFixed(2).replace(/,/g, " ").replace(".", ",") + " $"; its working to an extend: for example: using the regular expression 125900 is coming as 125900,00 $ but i want something like 125 900,00 $

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.