0

That's my problem. I'm trying to saving my input value in 2 different variables and then making the sum I got a error:

var stcost = $("#item_cost").val(); //is 1.200 
var val2=(actval*stcost/100).toFixed(3); //is 1.200
console.log("val2 first value: "+val2); //val2 first value: 0.014
var val2=(val2 + stcost).toFixed(3); //ERROR: custom.js:225 Uncaught TypeError: (val2 + stcost).toFixed is not a function
    //at Object.myCallbackFunction [as onUpdate] (custom.js:225)
    //at _update (dataTables.cellEdit.js:68)
   // at jQuery.fn.init.updateEditableCell (dataTables.cellEdit.js:54)
    //at HTMLInputElement.onfocusout (index.php?r=aXRlbW1udGM:1)
console.log("cost: "+stcost);   
console.log("val2: "+val2);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

What's wrong with this code?

CodeF0x
  • 2,624
  • 6
  • 17
  • 28
Fabio
  • 85
  • 1
  • 2
  • 14
  • 2
    well because you are concatenating two strings together which results in a string which does not have a toFixed() method. `("0.014" + "1.200")` is `"0.0141.200"` – epascarello Jun 04 '18 at 16:02
  • So how can I make the sum??? Sorry but I really don't understand how can I fix it – Fabio Jun 04 '18 at 16:04
  • "0.0141.200" is the result that I getting without .ToFixed() – Fabio Jun 04 '18 at 16:06

0 Answers0