how to ignore "," while rounding off decimals using javascript? -
this question has answer here:
<html> <head></head> <body> <label class="xyz"> <span class="aaaa">rs. </span> 1,399.00 </label> <label class="xyz"> <span class="aaaa">rs. </span> 199.00 </label> <script> function deciremove(){ var = document.getelementsbyclassname('xyz'); for(var i=0; i< all.length; i++) { var x = all[i].childnodes[2].nodevalue; x= math.round(x); all[i].childnodes[2].nodevalue = x; } } deciremove(); </script> </body> </html>
in above code want rounding off decimals 2 values, when value 199.00 works n gives 199 when 1,399.00 gives nan. , because of ",". how ignore or delete ",".
replace commas.
x= math.round(x.replace(/,/g, ''));
Comments
Post a Comment