图集1/4

正文 1147字数 141,675阅读




Github地址
https://github.com/scurker/currency.js
Run code
Cut to clipboard

    安装
    npm install --save currency.js
    Run code
    Cut to clipboard

      引用
      <script src="currency.min.js"></script>
      Run code
      Cut to clipboard


        效果




        // Numbers currency(1); // => "1.00" currency(123); // => "123.00" // Decimals currency(1.00); // => "1.00" currency(1.23); // => "1.23" // Strings currency("1.23"); // => "1.23" currency("$12.30"); // => "12.30" currency("£1,234,567.89"); // => "1,234,567.89" // Currency let c1 = currency(1.23); let c2 = currency(4.56); currency(7.89).add(c1).add(c2); // => "13.68"
        Run code
        Cut to clipboard


          Vue封装 全局使用
          //货币金额 import currency from 'currency.js' Vue.prototype.currency = v => currency(v,{symbol:'¥'}); //currency(0.1).add(0.2).format() //{{ currency(order.order_total_money).format({symbol:'$'}) }} //只格式化金额¥ Vue.prototype.fmtMoney = value => Vue.prototype.currency(value).format(); //{symbol:'$'} //fmtMoney(order.order_total_money) //end
          Run code
          Cut to clipboard