-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,030
  • 21
  • 100
  • 124
awariat
  • 286
  • 4
  • 19

4 Answers4

1

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

var grossTotal= +netPrice + +vatTotal;
Wassim Ben Hssen
  • 481
  • 5
  • 20
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,019
  • 1
  • 11
  • 18
0

Try with type conversion:

 var answer = parseInt(netPrice ) + parseInt(vatTotal);
Pergin Sheni
  • 315
  • 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,372
  • 2
  • 33
  • 41