目的地-Destination 前程似锦、未来可期、寻得良人、共赴白头,祝你也祝我。
博主 目的地-Destination
沪ICP备16003146号-2沪公网安备 31010702004922号萌ICP备20238488号博主 昨天 17:25 在线自豪地使用 Typecho 建站搭配使用 🌻Sunny 主题当前在线 72 人
歌曲封面 未知作品

沪ICP备16003146号-2

沪公网安备 31010702004922号

萌ICP备20238488号

网站已运行 7 年 341 天 23 小时 4 分

Powered by Typecho & Sunny

72 online · 95 ms

Title

Js/JQuery将数字金额转换为其他国家货币格式(包括货币符号和千分符)

Chrison

·

烂笔头

·

Article
⚠️ 本文最后更新于2022年12月12日,已经过了680天没有更新,若内容或图片失效,请留言反馈

结果显示

♾️ 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>

现在已有 208 次阅读,2 条评论,0 人点赞
Author:Chrison
作者
Js/JQuery将数字金额转换为其他国家货币格式(包括货币符号和千分符)
当前文章累计共 2002 字,阅读大概需要 1 分钟。
Java对List列表进行分组处理(对List列表固定分组/对List列表平均分组)
2022年12月13日 · 0评论
MySQL自定义函数实现金额转大写
2022年12月9日 · 2评论
李荣浩 - 歌曲分享
2023年2月12日 · 0评论
Comment:共2条
发表
  1. 头像
    @
    海角七号
    可以可以,正是我想要的!!!
    · Safari · 中国江苏省苏州市电信

    👍

    💖

    💯

    💦

    😄

    🪙

    👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
    1. 头像
      @
      该回复疑似异常,已被系统拦截!
      · Safari · 中国江苏省南京市电信

      👍

      💖

      💯

      💦

      😄

      🪙

      👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 不再显示
博主