* I WANT TO ROUND A NUMBER, BUT I WANT TO PUT A CONDITION *
Math.Truncate(6.847457) //resultado 6
* But this truncates all the numbers I just want to truncate the 5 and the others if you round them *
* I WANT TO ROUND A NUMBER, BUT I WANT TO PUT A CONDITION *
Math.Truncate(6.847457) //resultado 6
* But this truncates all the numbers I just want to truncate the 5 and the others if you round them *
The truth is that I do not know what language is that (Math.truncate) but it is not php. I give you the answer in php, which is what you ask according to the label you have marked:
$valor //tu valor
$parte_entera = (int) $valor;
if($parte_entera == 5){
$valor = $parte_entera;
}
else{
$valor = round($valor);
}
Another way (the same in reality):
$valor = (floor($valor) == 5) ? 5 : round($valor);
You must use the round()
php method. This method accepts three parameters: value, precision and mode.
With the third parameter, mode, you can achieve what you want like this:
if($numero == 5){
$numero = round($numero, 2, PHP_ROUND_HALF_DOWN)
}
Here the documentation of the method: link