标签:var res toc string substring unit return == math
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万
标签:var res toc string substring unit return == math
原文地址:https://www.cnblogs.com/bad-guy/p/10998725.html