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
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);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.