SOURCE

function truncator(numToTruncate, intDecimalPlaces) {    
    let numPower = Math.pow(10, intDecimalPlaces); // "numPowerConverter" might be better
    return ~~(numToTruncate * numPower)/numPower;

}
console.log(truncator(300,2))
console.log(truncator(2.9798989,2))
console 命令行工具 X clear

                    
>
console