简体   繁体   English

格式货币正则表达式javascript

[英]format currency regular expression javascript

I need to display a formatted number on a web page using JavaScript. 我需要使用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. 我正在尝试使用正则表达式和JavaScript来设置英语和法语的货币格式。 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. 所以我的5000转换为$ 5,000.00很好。

I need French to looks like this 5 000,00 $ 我需要法语看起来像这样5 000,00 $

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

用它来表示英文格式的num。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM