How to truncate a number from left in Node.js

1 Answer

0 votes
function truncate_left(num) {
    const total = parseInt(Math.log10(num));
     
    const first_digit = parseInt(num / parseInt(Math.pow(10,(total))));
 
    return num - first_digit * parseInt(Math.pow(10,(total)));
}
 
const num = 7483;
 
console.log(truncate_left(num));
 
 
 
 
/*
run:
 
483
 
*/

 



answered Jan 11, 2024 by avibootz

Related questions

2 answers 151 views
1 answer 115 views
1 answer 109 views
1 answer 149 views
1 answer 112 views
112 views asked Jan 11, 2024 by avibootz
1 answer 94 views
...