javascript - JS Numbers - 在 .fixed 之后使用区域设置字符串

标签 javascript jquery html regex

我正在使用 Money.js,一个用于转换货币的插件,并设置 div 的内容,如下所示:

currentDiv.html("<div>" + currentPrice + "</div><div class='converted'> " + rate.toFixed(0) + "</div>");

我尝试在每三位数字后用逗号分隔数字,并尝试将 .toLocaleString 添加到该行,但无法使其正常工作。

整夜都在这里寻找不同的解决方案,例如使用正则表达式等,但还没有找到任何东西......有什么想法吗?

这是全部代码:

<script src="https://raw.githubusercontent.com/openexchangerates/money.js/master/money.js"></script>
<script src="https://cdn.rawgit.com/openexchangerates/money.js/master/money.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>


<div class="hello">
  2300
</div>

<div class="hello">
  52400
</div>


<script>
$(".hello").each(function() {

var currentDiv = $(this);
var currentPrice = currentDiv.text();

var demo = function(data) {
    fx.rates = data.rates
    var rate = fx(currentPrice).from("GBP").to("USD");
    currentDiv.html("<div>"+currentPrice +"</div><div id='converted'> " +rate.toFixed(0)+"</div>");

}
    $.getJSON("http://api.fixer.io/latest", demo);
});

</script>

最佳答案

因为它是货币,所以末尾会有.##,对吗?

/^(?!0+\.00)(?=.{1,9}(\.|$))(?!0(?!\.))\d{1,3}(,\d{3})*(\.\d+)?$/

关于javascript - JS Numbers - 在 .fixed 之后使用区域设置字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36143013/

相关文章:

javascript - 如何找到选项卡关闭并清除本地存储

javascript - SailsJs Controller 上下文

javascript - 将对象设置为在 ngoptions 中选中

javascript - Jquery 插件冲突

jquery - LavaLamp 菜单在我的菜单上不起作用

javascript - 无法使用 gmaps.js 显示 map

javascript - 仅跟踪嵌套 div 标记中悬停子元素的鼠标移动

c# - MVC的Display装饰器和使用EditorFor应用的View是什么关系?

javascript - 如何确定可见 jqGrid 网格的 ID?

javascript - 如何在不使用任何 api 的情况下从 LinkedIn 抓取数据