简体   繁体   English

使用 jQuery 将小数位限制为 1

[英]Limit decimal places to 1 using jQuery

Either rounded or truncated:四舍五入或截断:

<div class="my-val">1.334</div>
<div class="my-val">12.133</div>

Should display as应该显示为

1.3 1.3

12.1 12.1

Try to use the callBack function of text function along with Number.toFixed() to achieve what you want,尝试使用text函数的callBack函数和Number.toFixed()来实现你想要的,

$(".my-val").text(function(_,text){
  return parseFloat(text).toFixed(1);
});

DEMO演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM