Casi he terminado con un proyecto de calculadora de conversión de scrimba, pero no he tenido éxito con el redondeo de números a 3 decimales.
He jugado con math.round / math.floor sin éxito. ¡Cualquier sugerencia sera apreciada!
Aquí hay un fragmento de mi trabajo:
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);