Skip to content

Commit

Permalink
fix(statistic): decimalPlaces=0时数值动画期间精度错误 (#3327)
Browse files Browse the repository at this point in the history
* fix(statistic): decimalPlaces=0时数值动画期间精度错误

* fix(statistic): 改为使用getFormatValue方法
  • Loading branch information
huangchen1031 authored Jan 16, 2025
1 parent 80f67ca commit 02953a1
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/statistic/Statistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import useIsFirstRender from '../hooks/useIsFirstRender';

import Skeleton from '../skeleton';
import Tween from '../_common/js/statistic/tween';
import { COLOR_MAP } from '../_common/js/statistic/utils';
import { COLOR_MAP, getFormatValue } from '../_common/js/statistic/utils';

export interface StatisticProps extends TdStatisticProps, StyledProps {}

Expand Down Expand Up @@ -85,13 +85,9 @@ const Statistic = forwardRef<StatisticRef, StatisticProps>((props, ref) => {
if (isFunction(format)) {
return format(formatInnerValue);
}
const options = {
minimumFractionDigits: decimalPlaces || 0,
maximumFractionDigits: decimalPlaces || 20,
useGrouping: !!separator,
};

// replace的替换的方案仅能应对大部分地区
formatInnerValue = formatInnerValue.toLocaleString(undefined, options).replace(/,|/g, separator);
formatInnerValue = getFormatValue(formatInnerValue, decimalPlaces, separator);

return formatInnerValue;
}, [innerValue, decimalPlaces, separator, format]);
Expand Down

0 comments on commit 02953a1

Please sign in to comment.