gpt4 book ai didi

javascript - 添加逗号到我的字符串

转载 作者:行者123 更新时间:2023-12-01 02:47:01 27 4
gpt4 key购买 nike

我需要帮助在 calcMileagePoints 函数中向 MileagePointsObj.innerHTML 添加逗号。现在它设置为四舍五入到最接近的 10。

<script type="text/javascript">     
window.onload=function() {
LapTimeObj = document.getElementById('InputLaptime');
RaceLengthObj = document.getElementById('InputRaceLength');
MileagePointsObj = document.getElementById('TDMileagePoints');
document.getElementById('btnReset').onclick = resetInputs;
document.getElementById('btnCalc').onclick = calcMileagePoints;
}
function resetInputs() {
LapTimeObj.value = '';
RaceLengthObj.value = '';
MileagePointsObj.innerHTML = '';
}
function calcMileagePoints() {
var LapTime = new Number(LapTimeObj.value);
var RaceLength = new Number(RaceLengthObj.value);
MileagePointsObj.innerHTML = '';

MileagePointsObj.innerHTML = parseInt(((RaceLength*60*60)/LapTime)*10 / 10, 10) * 10;
}
</script>

提前致谢!

杰罗姆

最佳答案

正如评论中所述,使用 toLocaleString()

简单的例子

let number = 123456789;
let numberWithComma = number.toLocaleString();
console.log(numberWithComma);

关于javascript - 添加逗号到我的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47190238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com