我正在使用money.js,一个用于兑换货币的插件,并将div的内容设置如下:
currentDiv.html("<div>" + currentPrice + "</div><div class='converted'> " + rate.toFixed(0) + "</div>");我正在尝试用逗号隔开每三个数字后面的数字,并尝试将.toLocaleString添加到行中,但无法使其工作。
我整晚都在这里寻找不同的解决方案,比如使用正则表达式等,但还没有找到任何yet...any的想法?
这是所有的代码:
<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>发布于 2016-03-22 08:10:09
因为它是货币,所以它的末尾会有.##,对吗?
/^(?!0+\.00)(?=.{1,9}(\.|$))(?!0(?!\.))\d{1,3}(,\d{3})*(\.\d+)?$/https://stackoverflow.com/questions/36143013
复制相似问题