fix: percent field component should support decimal point (#2966)

This commit is contained in:
katherinehhh 2023-11-05 16:51:59 +08:00 committed by GitHub
parent 59854085b2
commit a42ee95e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,12 @@
import { connect, mapReadPretty } from '@formily/react';
import { isNumberLike } from '@formily/shared';
import { isNum } from '@formily/shared';
import { InputNumber } from 'antd';
import * as math from 'mathjs';
import React, { useMemo } from 'react';
import { ReadPretty } from '../input-number/ReadPretty';
const isNumberLike = (index: any): index is number => isNum(index) || /^-?\d+(\.\d+)?$/.test(index);
const toValue = (value: any, callback: (v: number) => number) => {
if (isNumberLike(value)) {
return math.round(callback(value), 9);