0
<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 all = 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 i want Rounding Off Decimals two values, when a value is 199.00 it works well n gives 199 but when 1,399.00 it gives NaN. and this is because of ",". so how do i ignore or delete ",".

Pooja Desai
  • 227
  • 1
  • 6
  • 16

2 Answers2

2

Replace the commas.

x= Math.round(x.replace(/,/g, ''));
Ruel
  • 15,438
  • 7
  • 38
  • 49
0

You need to replace the "," with ""

  x= Math.round(x.replace(/\,/g,''));

DEMO

Ashwin Singh
  • 7,197
  • 4
  • 36
  • 55