javascript - Add two variables using jquery -


var = 1; var b = 2; var c = a+b; 

c show 12; need 3

how do using jquery?

it looks have strings , not numbers, need parseint() or parsefloat() (if may decimals) here, this:

var = "1"; var b = "2"; var c = parseint(a, 10) + parseint(b, 10); //or: var c = parsefloat(a) + parsefloat(b); 

you can test difference here, it's worth noting these not jquery base javascript functions, isn't dependent on jquery library in way.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -