繁体   English   中英

舍入数字:公制-英制测量转换计算器/scrimba 项目

[英]rounding numbers: Metric-imperial measurements conversion calculator / scrimba project

我几乎完成了 scrimba 的转换计算器项目,但没有成功将数字舍入到 3 位小数。

我玩过math.round / math.floor但没有成功。 任何建议,将不胜感激!

这是我的工作片段:

 let feetOutput = document.getElementById("feet-output"); let meterOutput = document.getElementById("meter-output"); meterInput = document.getElementById("meter-input"); let mainInput = document.getElementById("main-input"); litterInput = document.getElementById("litter-input") feetInput = document.getElementById("feet-input"); document.getElementById("main-Input").value = ''; document.getElementById("main-Input").textContent = 0; function lengthConverter(valNum) { document.getElementById("feet-output").innerHTML = valNum * 3.281 + " Feet"; document.getElementById("meter-output").innerHTML = valNum / 3.281 + " meters"; document.getElementById("gallons-output").innerHTML = valNum / 3.785 + " gallons"; document.getElementById("litter-output").innerHTML = valNum * 3.785 + " liters"; document.getElementById("pounds-output").innerHTML = valNum * 2.205 + " pounds"; document.getElementById("kg-output").innerHTML = valNum / 2.205 + " kilograms"; } function lengthConvertermf(valNum) { document.getElementById("feet-output").innerHTML = roundedUp((((valNum * 10) * (3.281 * 10)) / 10) * 1000 / 1000 + " Feet"); } function lengthConverterfm(valNum) { document.getElementById("meter-output").innerHTML = (((((valNum * 10) / (3.281 * 10) / 10) * 1000) / 1000) + " meters"); Math.round((num + Number.EPSILON) * 100) / 100 } function lengthConverterlg(valNum) { document.getElementById("gallons-output").innerHTML = roundedUp(valNum / 3.785 + " gallons"); } function lengthConvertergl(valNum) { document.getElementById("litter-output").innerHTML = roundedUp(valNum * 3.785 + " liters"); } function lengthConverterkp(valNum) { document.getElementById("pounds-output").innerHTML = roundedUp(valNum * 2.205) + " pounds"; } function lengthConverterpk(valNum) { document.getElementById("kg-output").innerHTML = roundedUp(valNum / 2.205 + " kilograms"); }

 const round = (num, n) => Number.parseFloat(num.toFixed(n)); //using: console.log(round(3.14159, 3)); const floor = (num, n) => Number.parseFloat(num.toFixed(n)) - Math.pow(10, -n);

暂无
暂无

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

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