How can I truncate a decimal number with zeros to the right, since it always truncates to the natural number, that is, if there is a 0 it does not take it?
function myRound(num, dec) {
var exp = Math.pow(10, dec || 2); // 2 decimales por defecto
return parseInt(num * exp, 10) / exp;
}
var num = 2.70;
console.log('Con 1 decimales:', myRound(num, 1));
console.log('Con 2 decimales:', myRound(num));
console.log('Con 3 decimales:', myRound(num, 3));
<html>
<head>
</head>
<body>
</body>
</html>