JSFiddle - React, Tailwind, and code Playground
HTML
<p>Trying to round 1.005. Result should be 1.01</p>
<p>
<div>Number((1.005).toFixed(2)); </div>
<div class="result1">Result: </div>
</p>
<p>
<div>Math.round(1.005*100)/100; </div>
<div class="result2">Result: </div>
</p>
<p>
<div>Number(Math.round(1.005+'e2')+'e-2');</div>
<div class="result3">Result: </div>
</p>
CSS
.result1, .result2{
color: red;
}
.result3{
color: green;
}
JavaScript
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
$('.result1').append(Number(1.005).toFixed(2));
$('.result2').append(Math.round(1.005*100)/100);
$('.result3').append(round(1.005, 2));