Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Targeting table cells for huge data edits Reply To: Targeting table cells for huge data edits

#167839
dyr
Participant

jQuery + regex should do the trick.

var rx = /\$([0-9]+)/g; // looks for a dollar sign followed by 1 or more digits
$('td').each(function(){
  var data = $(this).html();
  if( rx.test(data) ) { // if this TD has a match in it
    $(this).html(data.replace(rx, function(m, c) {
      return '$' + (c*1.3).toFixed(2); // c*1.3 yields some numbers with many decimal places, but toFixed(2) rounds off to just 2
    }));
  }
});

You could use toFixed(0) if you want to remove any partial dollar amounts.

Let me know if you have trouble.