结果显示
♾️ text 代码:123536.8546 转换为越南盾---> 123.536,85 ₫
6536.846 转换为人民币---> ¥6,536.85
JavaScript代码
♾️ text 代码:// 转换为越南盾
function numToVnFormatter(s) {
var persianDecimal = new Intl.NumberFormat("vi-VN",
{ style: "currency", currency: "VND",useGrouping: true,currencyDisplay: "symbol", maximumFractionDigits: 2 }
);
return persianDecimal.format(s);
}
//转换为人民币
function numToCnFormatter(s) {
var persianDecimal = new Intl.NumberFormat("zh-CN",
{ style: "currency", currency: "CNY",useGrouping: true,currencyDisplay: "symbol", maximumFractionDigits: 2 }
);
return persianDecimal.format(s);
}
如上述js,其他国家只需要更换NumberFormat中对应的国家currency及国际化地区语言码即可.立即查看各国对照表
调用方式
♾️ text 代码:numToVnFormatter (123536.8546)
完整Demo
♾️ text 代码:<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function numToVnFormatter(s) {
var persianDecimal = new Intl.NumberFormat("vi-VN",
{ style: "currency", currency: "VND",useGrouping: true,currencyDisplay: "symbol", maximumFractionDigits: 2 }
);
return persianDecimal.format(s);
}
function numToCnFormatter(s) {
var persianDecimal = new Intl.NumberFormat("zh-CN",
{ style: "currency", currency: "CNY",useGrouping: true,currencyDisplay: "symbol", maximumFractionDigits: 2 }
);
return persianDecimal.format(s);
}
$(function(){
$("#div1").text('123536.8546 转换为越南盾---> '+numToVnFormatter (123536.8546));
$("#div2").text('6536.846 转换为人民币---> '+numToCnFormatter(6536.846));
});
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
👍
💖
💯
💦
😄
🪙
博主
Chrison @海角七号👍
💖
💯
💦
😄
🪙