Home » Jquery » javascript – Is possible to add NUMBER value return in Js?-Exceptionshub

javascript – Is possible to add NUMBER value return in Js?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I am using Javascript. In success function, I am getting some results and storing in var say “baldet” in JS-CODE.

example:

success: function (result) {
        baldet = result;

        console.log(baldet[0].cleavebalance);

        if (openmon == 1){
        $("#clvbalance").val(baldet[0].cleavebalance);
    }
    }

from baldet[0].cleavebalance I am getting 2. My condition is if openmon == 1 then I want to add number 1 in it.

NOTE: add means SUM, not CONCAT()

So that i could get, 2 (from “baldet[0].cleavebalance” + 1 (number i want to add)) i.e. 2 + 1 = 3.

and show in $(“#clvbalance”).val(“3”); // value 3 is after getting SUM RESULT

Currently, I am getting “21” instead of “3”

I hope I made my query clear. Any help will be appreciated.

How to&Answer:

You need to parse from string to number like below

console.log("2" + 1); // dose not parse

console.log(parseInt("2") + 1)