JSFiddle - React, Tailwind, and code Playground

by ChrisStanyon

HTML

<table>
    <tr><th>Income</th><th>Cost</th><th>Percentage</th></tr>
    <tr><td>£100.00</td><td>£25.00</td><td></td></tr>    
    <tr><td>£500.00</td><td>£50.00</td><td></td></tr>    
    <tr><td>£1000.00</td><td>£200.00</td><td></td></tr>    
</table>

CSS

.red { background-color:red; }

JavaScript

$('tr').not(':eq(0)').each(function(i, row) {
    income = Number($('td:eq(0)',this).text().replace(/[^0-9\.]+/g,""));
    cost = Number($('td:eq(1)',this).text().replace(/[^0-9\.]+/g,""));
    percentage = (income - cost) / income * 100;
    $('td:eq(2)',this).text(Math.round(percentage) + '%');
})