diff --git a/src/libs/NumberUtils.ts b/src/libs/NumberUtils.ts index 477ac8464d57..6e8d0fa4362b 100644 --- a/src/libs/NumberUtils.ts +++ b/src/libs/NumberUtils.ts @@ -71,4 +71,14 @@ function generateRandomInt(a: number, b: number): number { return Math.floor(lower + Math.random() * (upper - lower + 1)); } -export {rand64, generateHexadecimalValue, generateRandomInt, clampWorklet}; +/** + * Parses a numeric string value containing a decimal separator from any locale. + * + * @param value the string value to parse + * @returns a floating point number parsed from the string value + */ +function parseFloatAnyLocale(value: string): number { + return parseFloat(value ? value.replace(',', '.') : value); +} + +export {rand64, generateHexadecimalValue, generateRandomInt, clampWorklet, parseFloatAnyLocale}; diff --git a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js index bdbcd1919257..026441c665a2 100644 --- a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js +++ b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js @@ -22,6 +22,7 @@ import ROUTES from '../../../ROUTES'; import getPermittedDecimalSeparator from '../../../libs/getPermittedDecimalSeparator'; import * as BankAccounts from '../../../libs/actions/BankAccounts'; import * as ReimbursementAccountProps from '../../ReimbursementAccount/reimbursementAccountPropTypes'; +import * as NumberUtils from '../../../libs/NumberUtils'; const propTypes = { /** Bank account attached to free plan */ @@ -86,7 +87,7 @@ class WorkspaceRateAndUnitPage extends React.Component { } getNumericValue(value) { - const numValue = parseFloat(value.toString().replace(',', '.')); + const numValue = NumberUtils.parseFloatAnyLocale(value.toString()); if (Number.isNaN(numValue)) { return NaN; } @@ -137,7 +138,7 @@ class WorkspaceRateAndUnitPage extends React.Component { const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{1,3})?$`, 'i'); if (!rateValueRegex.test(values.rate) || values.rate === '') { errors.rate = 'workspace.reimburse.invalidRateError'; - } else if (parseFloat(values.rate) <= 0) { + } else if (NumberUtils.parseFloatAnyLocale(values.rate) <= 0) { errors.rate = 'workspace.reimburse.lowRateError'; } return errors;