Reputation: 725
Either rounded or truncated:
<div class="my-val">1.334</div>
<div class="my-val">12.133</div>
Should display as
1.3
12.1
Upvotes: 1
Views: 30
Reputation: 67217
Try to use the callBack
function of text
function along with Number.toFixed()
to achieve what you want,
$(".my-val").text(function(_,text){
return parseFloat(text).toFixed(1);
});
Upvotes: 1