I am trying to write some code that will do the following;
- Add an ID to nth child
- Format the number in nth child to 2 decimal places
- Apply £ in front of the numbers
- Loop until every nth child in a table is done
I have numbers such as this to round of “0.7823076923076923” using the code I have I can get it to round up to "1" but I need it to round to 0.78 I then added “toFixed(2)” and it takes my “1” and puts it to “1.00” but I need It to go to “0.78” once I have that in place I can then look at how I can loop the code, but small steps.
Thanks for all the help.
Code:
<script>
$(document).ready(function(){
$('table>tbody>tr>td:nth-child(5n)').prop('id', 'test');
$('#test').text(function(i,v) {
return Math.round(parseInt(v * 100) / 100).toFixed(2);
});
});
</script>
UPDATE i got it working!!!
$(document).ready(function(){
$('table>tbody>tr>td:nth-child(5n)').prop('id', 'test');
var test = parseFloat($('#test').text()).toFixed(2);
$('table>tbody>tr>td:nth-child(5n)').empty().append(test);
});
now to make it loop,
Thanks for all the help.