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万