【发布时间】:2020-09-11 06:42:59
【问题描述】:
我想删除结果值中的小数逗号,并以逗号作为千位分隔符打印数字。
这是我正在使用的代码;
我的 HTML
<form>
<div>
<h3>do</h3>
<input type="text" id="value1">times
<h4>done</h4>
<input type="text" id="value2">times
<br>
</div>
<br>
<button type="button" onclick="cal()"> calculate </button>
<h6 id="result"></h6>
</form>
JS
<script>
const cal = () => {
const A = value1.value,
B = value2.value;
const res = A * (5/100) * (100 / B);
result.innerText = `your have things around ${res.toString().replace(".", ",")}times.`;
}
</script>
谢谢。
【问题讨论】:
-
您可能想看看 ECMAScript 国际化 API,尤其是 NumberFormat 函数
标签: javascript decimal comma