diff --git a/src/components/react-hook-form/numbers/float-input.js b/src/components/react-hook-form/numbers/float-input.js index b9fbe106..478229f4 100644 --- a/src/components/react-hook-form/numbers/float-input.js +++ b/src/components/react-hook-form/numbers/float-input.js @@ -15,6 +15,15 @@ const FloatInput = (props) => { if (['-', '.'].includes(sanitizedValue)) { return sanitizedValue; } + + // support editing exponential format + if ( + sanitizedValue && + (sanitizedValue.includes('e') || sanitizedValue.includes('E')) + ) { + return sanitizedValue; + } + return sanitizedValue === null || isNaN(sanitizedValue) ? '' : sanitizedValue; @@ -32,6 +41,12 @@ const FloatInput = (props) => { if (tmp.endsWith('.') || tmp.endsWith('0')) { return tmp; } + + // support editing exponential format + if (tmp.includes('e') || tmp.includes('E')) { + return tmp; + } + return parseFloat(tmp) || null; }; diff --git a/src/components/react-hook-form/numbers/utils.js b/src/components/react-hook-form/numbers/utils.js index 84475585..87aa4bc4 100644 --- a/src/components/react-hook-form/numbers/utils.js +++ b/src/components/react-hook-form/numbers/utils.js @@ -3,5 +3,5 @@ export const isIntegerNumber = (val) => { }; export const isFloatNumber = (val) => { - return /^-?[0-9]*[.,]?[0-9]*$/.test(val); + return /^-?[0-9]*[.,]?[0-9]*([eE][-+]?[0-9]*)?$/.test(val); };