/** * @description: 数字字符串前补齐数字0 * @param {number|string} num 待处理的数字 * @param {number} figures 处理后的数字字符串位数 * @param {boolean} isCut - 是否截取超出位 default: false * @return {string} */ export function keepNumberFigures(num, figures, isCut = false) { const preZero = Array.from({ length: figures }, _ => 0).join(''); try { const intNUm = BigInt(num).toString(); if (intNUm.length >= figures && !isCut) { // 长度足够且不需要截取 return intNUm; } // 截取字符串 const res = `${preZero}${intNUm}`.slice(-figures); return res; } catch (error) { console.error(error); return preZero; } }
标签:intNUm,return,数字,num,figures,字符串,补齐 From: https://www.cnblogs.com/qiang-ling/p/17168687.html