rapid-spreadjs 1.0.183 → 1.0.184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -16758,6 +16758,79 @@ const FormulaUtils = {
16758
16758
  // return calcVal(retArrVals[0], accuracy);
16759
16759
  },
16760
16760
  },
16761
+ {
16762
+ funName: 'YJROUNDKX',
16763
+ funDesc: '计算科学计数修约',
16764
+ funDefaultVal: null,
16765
+ funParams: [
16766
+ {
16767
+ name: '数值',
16768
+ repeatable: false,
16769
+ optional: false,
16770
+ },
16771
+ {
16772
+ name: '修约位数',
16773
+ repeatable: false,
16774
+ optional: false,
16775
+ },
16776
+ ],
16777
+ funCallback: (spread, sheet, retData) => {
16778
+ let symbol = '/';
16779
+ //如果传递的参数小于2个(第一个参数为修约的数值,第二个参数为修约位数),则返回符号
16780
+ if (retData.allCellVals.length < 2) {
16781
+ return symbol;
16782
+ }
16783
+ //判断要修约的值和精度是否为数字,不是则返回符号
16784
+ if (!FormulaUtils.commFun.isNumber(retData.allCellVals[0]) || !FormulaUtils.commFun.isNumber(retData.allCellVals[1])) {
16785
+ return symbol;
16786
+ }
16787
+ let retArrVals = FormulaUtils.commFun.convertToInt(retData.allCellVals);
16788
+ //修约位数(正式以配置中为优先级获取,如业务系统中就要根据配置来判断)
16789
+ let accuracy = Math.floor(retArrVals[1]);
16790
+ //小于等于0时,返回原始数据
16791
+ if (accuracy <= 0 || retArrVals[0] == 0) {
16792
+ return retArrVals[0];
16793
+ }
16794
+ /**
16795
+ * 将数字转换为统一的标准科学计数法表达字符串
16796
+ * @param {number} num - 需要转换的数字
16797
+ * @param {number} [digits] - 有效数字位数(默认自动推断)
16798
+ * @returns {string} 如 "1.34*10^-2"、"1.34"、"1.34*10³"
16799
+ */
16800
+ const toScientificNotation = (num, digits) => {
16801
+ if (num === 0)
16802
+ return '0';
16803
+ if (!isFinite(num))
16804
+ return String(num);
16805
+ // 1. 确定有效数字位数:未指定时从原数推断
16806
+ if (digits === undefined) {
16807
+ const str = String(Math.abs(num));
16808
+ // 去除小数点和前导零,剩余即为有效数字
16809
+ digits = str.replace(/^0*\.?0*/, '').replace('.', '').length || 1;
16810
+ }
16811
+ // 2. 利用 toExponential 获取标准化系数和指数
16812
+ // 例如: (134).toExponential(2) => "1.34e+2"
16813
+ const expStr = num.toExponential(digits - 1);
16814
+ const [coefStr, expPart] = expStr.split('e');
16815
+ const exponent = parseInt(expPart, 10);
16816
+ // 3. 清理系数尾部多余的零(如 1.340 → 1.34)
16817
+ const coefficient = parseFloat(coefStr).toString();
16818
+ // 4. 根据指数值格式化输出
16819
+ if (exponent === 0) {
16820
+ // 指数为0:直接返回系数,如 "1.34"
16821
+ return coefficient;
16822
+ }
16823
+ // 上标映射表
16824
+ const superscripts = { '-': '⁻', '0': '⁰', '1': '¹', '2': '²', '3': '³', '4': '⁴', '5': '⁵', '6': '⁶', '7': '⁷', '8': '⁸', '9': '⁹' };
16825
+ const expDisplay = String(exponent)
16826
+ .split('')
16827
+ .map((ch) => superscripts[ch] || ch)
16828
+ .join('');
16829
+ return `${coefficient}*10${expDisplay}`;
16830
+ };
16831
+ return toScientificNotation(retArrVals[0], accuracy);
16832
+ },
16833
+ },
16761
16834
  {
16762
16835
  funName: 'YJDZ',
16763
16836
  funDesc: '按照单元格点选顺序,优先提取最后一个有数据的单元格值',