Floating point

Hi all.
I did some calculation and the result appears like this
17.2962962963%

how should I change it to 2 floating point= 17.30%

the variable for the result value come from
.($Totalrank[$temp_i]/$total_weight)*100

to make it easier i assigned it to another value
$weight.

where and how should I change so that I get the value as mentioned above?
many thanks


$value = 17.2962962963 ;
$value = round($value, 2);

That should do it. More information at http://www.php.net/round

ok, thanks

You can also use printf() when all you need the rounded representation for is output.


$weight = $Totalrank[$temp_i] / $total_weight * 100;
printf("Weight: %.2f\
", $weight);

This yields the benefit of retaining the precision from your calculation.