Merge branch 'main' into next

This commit is contained in:
nocobase[bot] 2025-02-12 13:17:46 +00:00
commit 34df510621
2 changed files with 14 additions and 7 deletions

View File

@ -13,14 +13,19 @@ import BigNumber from 'bignumber.js';
import { format } from 'd3-format';
import * as math from 'mathjs';
import React, { useMemo } from 'react';
import { toString } from 'lodash';
import { withPopupWrapper } from '../../common/withPopupWrapper';
function countDecimalPlaces(value) {
const number = Number(value);
if (!Number.isFinite(number)) return 0;
const strValue = toString(value);
const decimalPart = String(number).split('.')[1];
return decimalPart ? decimalPart.length : 0;
// 检查是否包含小数点
if (!strValue.includes('.')) return 0;
// 获取小数部分并去除末尾的零
const decimalPart = strValue.split('.')[1].replace(/0+$/, '');
return decimalPart.length;
}
const separators = {
'0,0.00': { thousands: ',', decimal: '.' },
@ -137,10 +142,10 @@ export function formatNumber(props) {
//单位换算
const unitData = formatUnitConversion(value, unitConversionType, unitConversion);
//精度换算
const preciationData = toFixedByStep(unitData, step);
const precisionData = toFixedByStep(unitData, step);
let result;
//分隔符换算
result = formatNumberWithSeparator(preciationData, separator, countDecimalPlaces(step), formatStyle);
result = formatNumberWithSeparator(precisionData, separator, countDecimalPlaces(step), formatStyle);
if (formatStyle === 'scientifix') {
//科学计数显示
result = scientificNotation(Number(unitData), countDecimalPlaces(step), separators?.[separator]?.['decimal']);
@ -170,7 +175,6 @@ export const ReadPretty: React.FC<InputNumberReadPrettyProps> = withPopupWrapper
const result = useMemo(() => {
return formatNumber({ step, formatStyle, value, unitConversion, unitConversionType, separator });
}, [step, formatStyle, value, unitConversion, unitConversionType, separator]);
if (!isValid(result)) {
return null;
}

View File

@ -115,6 +115,9 @@ export const SchemaSettingsNumberFormat = function NumberFormatConfig(props: { f
{ value: '0.001', label: '1.000' },
{ value: '0.0001', label: '1.0000' },
{ value: '0.00001', label: '1.00000' },
{ value: '0.000001', label: '1.000000' },
{ value: '0.0000001', label: '1.0000000' },
{ value: '0.00000001', label: '1.00000000' },
],
},
addonBefore: {