error javascript code calculation -


pls consider calculation in javascript code below. example values:

  • investmentfix = 200.00
  • investmentvar = 123.12
  • nrofparts = 5.00

...the console shows strange result value 0200.00615.6. don't understand. noticed values 200.00 , 615.6, - latter result of investmentvar * nrofparts- in result value. i'd expect (and target get) result 815.6 (200+(123.12*5.00).

what goes wrong? relate kind of format issue?

javascript code:

var result =0;  result += (investmentfix + (investmentvar * nrofparts));  console.log(result); 

try following:

result = parsefloat(0,10); result+=parsefloat(investmendfix,10)+parsefloat(investmentvar*nrofparts,10); console.log(result); 

this ensures javascript engine parses variables @ numbers instead of strings.

parsefloat() syntax: parsefloat(mynumber,base);


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -