当前位置: 首页 > 工具软件 > accounting.js > 使用案例 >

Accounting.js库的使用

常子濯
2023-12-01

Accounting.js用来将一个数字格式化为货币格式
使用案例:

<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="math.js | basic usage">
  <title>math.js | basic usage</title>
  <script src="accounting.js"></script>
</head>
<body>
  <script>

    // functions and constants
    //格式化为美元,默认
    print(accounting.formatMoney(45998307)); // $45,998,307.00
    //也可以指定参数
    /*
    var options={
            symbol :"$",
            decimal:".",
            thousand:",",
            precision:2,
            format:"%s%v"
        }
     */
    //欧元形式
    print(accounting.formatMoney(4587.35,"€",3,".",","));//€4.587,350
    //也可以格式化整个一列数字:
    var list =[[455,12,3],[88,25,2],[667,825,14]];
    var c = accounting.format(list);//455,12,3,88,25,2,667,825,14
    print(c);
    print(accounting.formatColumn(list));//$455.00,$ 12.00,$ 3.00,$88.00,$25.00,$ 2.00,$667.00,$825.00,$ 14.00
    // helper function to output formatted results.
    function print(value) {
      var precision = 14;
      document.write(value + '<br>');
    }
  </script>
</body>
</html>

下载网站:http://openexchangerates.github.io/accounting.js/#download

 类似资料: