【发布时间】:2021-08-26 15:00:42
【问题描述】:
我正在查询我的数据库以返回一个双精度值。我的数据库中的这个值最多有 17 个小数位,但我只想在网页上显示 2 个小数位。
这是我的 html 表格。小数点的值进入 {{savings_percent}}
<table class="table text-light text-end">
<thead>
<tr>
<th scope="col">CHW</th>
</tr>
</thead>
<tbody class="text-end">
<tr id="decimal">
<th scope="row">%</th>
{{#with chw}}
<td class='rounded'>{{savings_percent}}</td>
{{/with}}
</tbody>
</table>
这就是我尝试获取该值的方式,将其转换为十进制,然后给它一个固定的两位小数。控制台给我 $(...).val(...).toFixed 不是一个函数。 有没有人可以解决这个问题?
let decimal = parseFloat($("#decimal .rounded").text())
window.onload = () => {
$('.rounded').val(decimal).toFixed(2)
console.log(decimal)
};
【问题讨论】:
标签: javascript jquery html-table decimal