mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
Merge branch 'main' into next
This commit is contained in:
commit
34df510621
@ -13,14 +13,19 @@ import BigNumber from 'bignumber.js';
|
|||||||
import { format } from 'd3-format';
|
import { format } from 'd3-format';
|
||||||
import * as math from 'mathjs';
|
import * as math from 'mathjs';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
import { toString } from 'lodash';
|
||||||
import { withPopupWrapper } from '../../common/withPopupWrapper';
|
import { withPopupWrapper } from '../../common/withPopupWrapper';
|
||||||
|
|
||||||
function countDecimalPlaces(value) {
|
function countDecimalPlaces(value) {
|
||||||
const number = Number(value);
|
const strValue = toString(value);
|
||||||
if (!Number.isFinite(number)) return 0;
|
|
||||||
|
|
||||||
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 = {
|
const separators = {
|
||||||
'0,0.00': { thousands: ',', decimal: '.' },
|
'0,0.00': { thousands: ',', decimal: '.' },
|
||||||
@ -137,10 +142,10 @@ export function formatNumber(props) {
|
|||||||
//单位换算
|
//单位换算
|
||||||
const unitData = formatUnitConversion(value, unitConversionType, unitConversion);
|
const unitData = formatUnitConversion(value, unitConversionType, unitConversion);
|
||||||
//精度换算
|
//精度换算
|
||||||
const preciationData = toFixedByStep(unitData, step);
|
const precisionData = toFixedByStep(unitData, step);
|
||||||
let result;
|
let result;
|
||||||
//分隔符换算
|
//分隔符换算
|
||||||
result = formatNumberWithSeparator(preciationData, separator, countDecimalPlaces(step), formatStyle);
|
result = formatNumberWithSeparator(precisionData, separator, countDecimalPlaces(step), formatStyle);
|
||||||
if (formatStyle === 'scientifix') {
|
if (formatStyle === 'scientifix') {
|
||||||
//科学计数显示
|
//科学计数显示
|
||||||
result = scientificNotation(Number(unitData), countDecimalPlaces(step), separators?.[separator]?.['decimal']);
|
result = scientificNotation(Number(unitData), countDecimalPlaces(step), separators?.[separator]?.['decimal']);
|
||||||
@ -170,7 +175,6 @@ export const ReadPretty: React.FC<InputNumberReadPrettyProps> = withPopupWrapper
|
|||||||
const result = useMemo(() => {
|
const result = useMemo(() => {
|
||||||
return formatNumber({ step, formatStyle, value, unitConversion, unitConversionType, separator });
|
return formatNumber({ step, formatStyle, value, unitConversion, unitConversionType, separator });
|
||||||
}, [step, formatStyle, value, unitConversion, unitConversionType, separator]);
|
}, [step, formatStyle, value, unitConversion, unitConversionType, separator]);
|
||||||
|
|
||||||
if (!isValid(result)) {
|
if (!isValid(result)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,9 @@ export const SchemaSettingsNumberFormat = function NumberFormatConfig(props: { f
|
|||||||
{ value: '0.001', label: '1.000' },
|
{ value: '0.001', label: '1.000' },
|
||||||
{ value: '0.0001', label: '1.0000' },
|
{ value: '0.0001', label: '1.0000' },
|
||||||
{ value: '0.00001', label: '1.00000' },
|
{ 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: {
|
addonBefore: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user