views:

34

answers:

5

Hi. Simple question. I have this code:

total = 41
win   = 48

       echo ($total/$win) * 100 ; 

printing out

85.416666666667

I need to remove the remainder so it prints out: 85 %.

+3  A: 
KennyTM
A: 

You can use the floor function:

echo floor(($total/$win) * 100) ; 
Sarfraz
+1  A: 

Use the round(); function.

<?php
$total = 41;
$win   = 48;

echo round(($total/$win)*100).' %'; 
?>
ahmet2106
+1  A: 

the elegant way would be to use string

number_format(float $number, int $decimals, string $dec_point, string $thousands_sep);

like this:

<?php
$total = 41;
$win   = 48;

echo number_format(($total/$win)*100,0,'.').' %'; 
?>
ITroubs
like this one, but in my case I have to use floor()
ganjan
then du so number_format(floor(($total/$win)*100),0,'.',',').' %'; i also added the missing fourth parameter for the number_format funcion. totally forgot that it takes either 2 or 4 parameters.
ITroubs
A: 

Too many possible ways, here is another one:

<?php
    echo sprintf( "%d %%", ( $total / $win ) * 100 );
?>
Salman A