From 2e98d406d8f88b411a7ef390d565b97d6862bd99 Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 24 Apr 2024 10:45:08 +0200 Subject: [PATCH] [fix]: float point precision bug in form validation --- src/features/experiment/Form.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/experiment/Form.tsx b/src/features/experiment/Form.tsx index 2c68cdb..4c9b0bf 100644 --- a/src/features/experiment/Form.tsx +++ b/src/features/experiment/Form.tsx @@ -121,7 +121,7 @@ const ExperimentFormComponent: React.FC = ({ onSubmit, return tot; }, 0); - if (sum != 1.0) setFormError('imbalancedCase', { type: 'required', message: t('features.experiment.form.errors.imbalancedCaseSumDistinctOfOne') as string }); + if ((Math.round(sum * 1e12) / 1e12) != 1.0) setFormError('imbalancedCase', { type: 'required', message: t('features.experiment.form.errors.imbalancedCaseSumDistinctOfOne') as string }); } } if (Validations.isBlank(data.name)) setFormError('name', { type: 'required', message: t('features.experiment.form.errors.nameRequired') as string })