我正在尝试格式化代理费收据表格(使用点。如您在下图所示,代理费收据号码来自5%Price。它会使用jquery自动计算并给出值5000。问题是如何格式化该数字并在命中千点时给出点?波纹管代码
<div class="form-group">
<label>Agent Fee received (Rp)</label>
<div class="input-group">
<input readonly type="text" class="form-control" id="agent_fee_received" name="agent_fee_received" autocomplete="off" maxlength="20">
<input type="hidden" name="agent_fees_received" id="agent_fees_received">
</div>
</div>
$(document).ready(function(){
var Tripagent_feeReceived = 0 ;
var Tripagent_fee = 0 ;
if (TripRatepercentage!="0")
{
Tripagent_fee = Trippublish_price-(Trippublish_price*(
TripRatepercentage/100));
Tripagent_feeReceived= Trippublish_price*(TripRatepercentage/100);
}
$("#agent_fee").val(Tripagent_fee);
$("#agent_fee_received").val(Tripagent_feeReceived);
}
答案 0 :(得分:0)
您可以自行实现。
function fmoney(s, n) {
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(),
r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").reverse().join("") + "." + r;
}
console.log(fmoney(1234.5678, 2));