[英]remove last zero after decimal in JavaScript
65.110 //result = 65.11
65.111 //result = 65.111
65.100 //result = 65.10
65.000 //result = 65.00
我試過下面的,但它不工作
round(3).replace(/(\.0+|0+)$/, '');
如果存在,您可以只替換最后一個零。
const format = number => number.toFixed(3).replace(/0$/, ''); console.log([65.110, 65.111, 65.100, 65.000].map(format));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.