-5

I have the following error:

jquery-3.4.1.min.js:2 The specified value "24.164.83" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?

Code

var grossTotal = netPrice * vatTotal // Is OK - it multiplies values

but

var grossTotal = netPrice + vatTotal // It makes this error -

it doesn’t sum.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
awariat
  • 331
  • 1
  • 5
  • 22

4 Answers4

1

The easiest way to produce a number from a string is prepend with +

var grossTotal= +netPrice + +vatTotal;
Wassim Ben Hssen
  • 519
  • 6
  • 23
0

Try this code:

var netPrice = 1.432;
var vatTotal = 14.423;
var grossTotal = parseFloat(netPrice) + parseFloat(vatTotal)// Change according to data type of netPrice and/or vatTotal
console.log(grossTotal);
uday8486
  • 1,203
  • 2
  • 13
  • 22
0

Try with type conversion:

 var answer = parseInt(netPrice ) + parseInt(vatTotal);
Pergin Sheni
  • 393
  • 2
  • 11
0

You can use this code, First format value using parseFloat

 var netPrice = 2.3777;
 var vatTotal = 1.3777;
 var grossTotal = parseFloat(netPrice ) + parseFloat(vatTotal);
 console.log(grossTotal);

     var netPrice = 2;
     var vatTotal = 1;
     var grossTotal = parseInt(netPrice ) + parseInt(vatTotal);
     console.log(grossTotal);

For more information about parseFloat

https://www.w3schools.com/jsref/jsref_parsefloat.asp

Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43