1

I am getting an error when trying to format a number:

The specified value "798,789.00" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?

 <FormField
    type="number"
    value={
      Number(
        startupFourthStepForm.previous_investments &&
          startupFourthStepForm.previous_investments[index] &&
          startupFourthStepForm.previous_investments[index].amount,
      )
        .toFixed(2)
        .replace(/\d(?=(\d{3})+\.)/g, '$&,') || ''
    }
  />

I am using Number since amount comes as a string. I am getting that error and I am not getting anything to render.

If I remove that regular expression and the toFixed method, I get 798789.00 in the input.

What am I missing?

Non
  • 8,409
  • 20
  • 71
  • 123

0 Answers0