javascript - How do you sum two values containing the dollar sign "$"? I have been trying to figure out the methods and properties, still no clue -


//for example  allinputs[22].value //equals $45 , allinputs[4].value  // equals $70  allinputs[22].value + allinputs[4].value = "$45$70" 

it equals "$45$70". want sum value. how sum both values final value ignoring dollar sign?

you can use

"$" + (parseint(allinputs[22].value.substring(1)) + parseint(allinputs[22].value.substring(1))) 

the substring method, rid of $ sign, , parseint convert number. need that, because if not use concatenate values strings. note put set of brackets sum numbers. because, when interpreter sees "$" thinks should concatenate strings. want sum numbers , concatenate sum "$" string.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -