Qual é a diferença entre andar e roda

         CODE                            RESULTS

$a = floor(3.5);                         //3
$b = round(3.5, 0, PHP_ROUND_HALF_DOWN); //3
var_dump($a);                            //float(3)
var_dump($b);                            //float(3)
$c = gettype($a);                        //double
$d = gettype($b);                        //double
Qual é a diferença?? quando uso piso() ou redondo() para o número acima.?

Author: Mr world wide, 2017-01-13

1 answers

floor() irá simplesmente baixar o valor decimal e devolver apenas um inteiro.

Então floor(1.2) => 1 e floor(1.9) => 1.

Entretanto round() will round number that has decimal value lower than 0.5 to lower int, and when more than 0.5 to higher int:

Então round(1.2) => 1 mas round(1.9) => 2

Também round() tem mais opções, como precisão e arredondamento.

 4
Author: Justinas, 2017-01-13 09:55:07