-
-
Save parzibyte/b2571ca62f91d75f21d35331a0b2e199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://parzibyte.me/blog | |
*/ | |
const redondear = numero => { | |
// .5 o menos, baja. Si no, sube | |
const diferencia = numero - parseInt(numero); | |
if (diferencia <= 0.5) { | |
return Math.floor(numero); | |
} else { | |
return Math.ceil(numero); | |
} | |
} | |
console.log(redondear(9.5)); // 9 | |
console.log(redondear(9.6)); // 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment