I have a table that tracks stock level changes, on most occasions the addition/subtraction is with whole numbers (-1, -2, +2, +3) etc. However, on some instances +0.5, -0.25 may be required. My current code get the correct values, but when it comes to decimals, it will on deduct or add to the nearest whole number (+1/-1). The oldValue and newValue variable are populated from a stock changes table and I'm displaying the number of change from stock.
Below is the calculation function -
formatDifference(change: StockChange) {
const difference = parseInt(change.newValue || '0', 10) - parseInt(change.oldValue || '0', 10);
return difference > 0 ? '+' + difference : difference;
}
HTML -
<td style="text-align: center;">
({{formatDifference(change)}})
<div class="stockLabel">
Difference
</div>
</td>