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 122 views
1 answer 143 views
1 answer 112 views
1 answer 153 views
1 answer 98 views
1 answer 105 views
105 views asked Jan 11, 2024 by avibootz
1 answer 125 views
125 views asked Jan 10, 2024 by avibootz
...