/* * @Author: your name * @Date: 2021-10-29 13:29:26 * @LastEditTime: 2021-11-12 14:50:47 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /data-show/src/utils/gol/dataTool.js */ /** * 大数字转换,将大额数字转换为万、千万、亿等 * @param value 数字值 */ export function bigNumberTransform(value) { const newValue = ['', '', ''] let fr = 1000 let num = 3 let text1 = '' let fm = 1 while (value / fr >= 1) { fr *= 10 num += 1 } if (num <= 4) { // 千 newValue[0] = parseInt(value / 1000) + '' newValue[1] = '千' } else if (num <= 8) { // 万 text1 = parseInt(num - 4) / 3 > 1 ? '千万' : '万' // tslint:disable-next-line:no-shadowed-variable fm = text1 === '万' ? 10000 : 10000000 if (value % fm === 0) { newValue[0] = parseInt(value / fm) + '' } else { newValue[0] = parseFloat(value / fm).toFixed(2) + '' } newValue[1] = text1 } else if (num <= 16) { // 亿 text1 = (num - 8) / 3 > 1 ? '千亿' : '亿' text1 = (num - 8) / 4 > 1 ? '万亿' : text1 text1 = (num - 8) / 7 > 1 ? '千万亿' : text1 // tslint:disable-next-line:no-shadowed-variable fm = 1 if (text1 === '亿') { fm = 100000000 } else if (text1 === '千亿') { fm = 100000000000 } else if (text1 === '万亿') { fm = 1000000000000 } else if (text1 === '千万亿') { fm = 1000000000000000 } if (value % fm === 0) { newValue[0] = parseInt(value / fm) + '' } else { newValue[0] = parseFloat(value / fm).toFixed(2) + '' } newValue[1] = text1 } if (value < 1000) { newValue[0] = value + '' newValue[1] = '' } return newValue.join('') } // 对数组中某个对象值由小到大进行排序 export function compare(property) { return function (a, b) { let value1 = a[property]; let value2 = b[property]; return value1 - value2; } } // 对数组中某个对象值由大到小进行排序 export function comparePig(property) { return function (a, b) { let value1 = a[property]; let value2 = b[property]; return value2 - value1; } } // 处理超出字后面... export function doStr(str, n) { let totalCount = 0; let txt = ""; for (var i = 0; i < str.length; i++) { let c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) { totalCount++; } else { totalCount += 2; } if (totalCount <= n) { txt += str[i]; } else { txt += '...'; return txt } } return txt; }