Skip to content

Commit

Permalink
fix(statistic): fix decimalPlaces setting 0 is invalid (#3496)
Browse files Browse the repository at this point in the history
* fix(statistic): fix decimalPlaces setting 0 is invalid

* chore: format code

* chore: del comment
  • Loading branch information
liweijie0812 authored and uyarn committed Feb 24, 2025
1 parent a3f2fef commit f9ce45d
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/statistic/statistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useGlobalIcon } from '../hooks/useGlobalIcon';

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 default defineComponent({
name: 'Statistic',
Expand Down Expand Up @@ -57,20 +57,11 @@ export default defineComponent({
};

const formatValue = computed(() => {
let _value: number | undefined | string = innerValue.value;

if (isFunction(props.format)) {
return props.format(_value);
return props.format(innerValue.value);
}
const options = {
minimumFractionDigits: decimalPlaces.value || 0,
maximumFractionDigits: decimalPlaces.value || 20,
useGrouping: !!separator,
};
// replace的替换的方案仅能应对大部分地区
_value = _value.toLocaleString(undefined, options).replace(/,|/g, separator.value);

return _value;
return getFormatValue(innerValue.value, decimalPlaces.value, separator.value);
});

onMounted(() => props.animation && props.animationStart && start());
Expand Down

0 comments on commit f9ce45d

Please sign in to comment.