计数操作

function autoConvertUnit(value) {
    var indexText = "";
    var index = value.indexOf("-");
    if (index != -1) {
        value = value.substring(index + 1);
        indexText = "-";
    }
    var k = 10000;
    if (value < k) return indexText + value;
    var sizes = ['', '万', '亿', '万亿'], i = Math.floor(Math.log(value) / Math.log(k));
    var result = (value / Math.pow(k, i)).toString();
    if (result.lastIndexOf('.') == -1) {
        return indexText + result + sizes[i];
    } else {
        return indexText + result.substring(0, result.lastIndexOf('.') + 3) + sizes[i];
    }
}

例如:4026200 ====》402.62万

posted on 2019-06-10 16:55  bad--guy  阅读(166)  评论(0编辑  收藏  举报

导航