1
I need a function to do the following, I get the number for example 15, and I need to turn it into a decimal 1.0, rounding the 5 to 0.
I tried to use the number_format(15, 1, '.', '')
, but he returns me 15.0
How can I do that?
1
I need a function to do the following, I get the number for example 15, and I need to turn it into a decimal 1.0, rounding the 5 to 0.
I tried to use the number_format(15, 1, '.', '')
, but he returns me 15.0
How can I do that?
0
Something like that?
<?php
$a = 15;
$b = $a / 10; //1,5
$c = floor($b); //1 - arredonda para baixo
var_dump($a, $b, $c); //para você verificar a transformação do número
echo number_format($c, 1, '.', ''); //para exibir '1.0'
The result of var_dump
is int(15) float(1.5) float(1)
i know the result, I wrote the code. I’m showing the number transformation
Adir I know you know the result, but whoever comes to see the question does not know.
Browser other questions tagged php codeigniter
You are not signed in. Login or sign up in order to post.
to make rounding you must use the function intval(), see also other mathematical functions. A simple division will solve the problem:
intval(15 / 10)
– Pedro Sanção
You typed 15, which is an integer number. Try changing the number to 1.5 to test
– Pedro Laini