How to truncate a number from left in PHP

1 Answer

0 votes
function truncate_left($num) {
    $total = floor(log10($num)); // total - 1 = 3
    
    $first_digit = (int)($num / pow(10, $total));

    return $num - $first_digit * pow(10, $total);
}
        
$num = 7483;

echo truncate_left($num);




/*
run:
       
483
       
*/

 



answered Jan 11, 2024 by avibootz

Related questions

1 answer 201 views
1 answer 218 views
1 answer 197 views
1 answer 240 views
1 answer 179 views
1 answer 186 views
186 views asked Jan 11, 2024 by avibootz
1 answer 212 views
212 views asked Jan 10, 2024 by avibootz
...