zoukankan      html  css  js  c++  java
  • 三位加,号

      function formatNum(str) {
        var newStr = "";
        var count = 0;
        // 当数字是整数
        if (str.indexOf(".") == -1) {
            for (var i = str.length - 1; i >= 0; i--) {
                if (count % 3 == 0 && count != 0) {
                    newStr = str.charAt(i) + "," + newStr;
                } else {
                    newStr = str.charAt(i) + newStr;
                }
                count++;
            }
            str = newStr ; //自动补小数点后两位
            return str;
        }
        // 当数字带有小数
        else {
            for (var i = str.indexOf(".") - 1; i >= 0; i--) {
                if (count % 3 == 0 && count != 0) {
                    newStr = str.charAt(i) + "," + newStr;
                } else {
                    newStr = str.charAt(i) + newStr; //逐个字符相接起来
                }
                count++;
            }
            str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
            return str;
        }
    }
  • 相关阅读:
    spring-mvc访问本地html文件
    好文收集
    jsp参数乱码解决
    ext window嵌jsp页面自适应
    正则学习(转)
    Error occurred during initialization of VM Incompatible initial and maximum heap sizes specified
    产品测试流程
    创建maven工程时报错,解决方案
    接口测试中如何利用cookies保持会话
    http协议基础
  • 原文地址:https://www.cnblogs.com/wsj1/p/14945131.html
Copyright © 2011-2022 走看看