Truncate integer value PHP [closed]

-3

I need to get the following result:

4,2 = 5
85,02 = 9
256,9 = 3...

For the time being, I used the code:

$novoservico = '402,02';
$novoservico = str_replace(",",".",$novoservico);
$valor_redondo = ceil($novoservico);
echo $valor_redondo; ?>

With this code, I can always round up the numbers:

4,2 = 5
85,02 = 86
256,9 = 257...

In this case, I need to make these numbers "truncated up". I do not know if I was very clear using that expression. But it was the best way to explain what I need to do. Thanks in advance. about any remark or doubt about the question, I am at your disposal.

    
asked by anonymous 05.06.2018 / 13:34

1 answer

0

If you want a 1-digit number only, you can do so:

$novoservico = '402,02';
$valor_redondo = $novoservico[0]+1;
echo $valor_redondo;

It will always print the next number, but if it is int really:

$valor_redondo = intval($novoservico[0]+1);
    
05.06.2018 / 13:45