This topic is locked

AVG Arrays Not Displaying Decimals Correctly

10/27/2008 12:18:57 PM
PHPRunner General questions
R
rgilani author

Hello,
Using PHP Runner 4.2, I have created a sort of attrition report that also calculates averages for the page totals, and global totals.
As our current data calculates, the result is 0.9abcdefg (where abcdefg are numbers right of the decimal point).
I tried formatting the number so that it will only display a number up to 2 decimal places, so if it was .9238485, it should output .92.
Tried using the number_format() and round() functions in PHP in front of the array but it would either round it to 1, or not display anything at all.
This is the code snippet that displays the 0.9abcdefg numbers:

$avg=array("CAN_QTY"=>$globaltotals_sum["CAN_QTY"] * 100 / $pagetotals_sum["CUST_QTY"]);

$smarty->assign("global_totalCAN_QTY_avg",GetData($avg,"CAN_QTY",""));


Attempted this:

$avg=number_format(array("CAN_QTY"=>$globaltotals_sum["CAN_QTY"] * 100 / $pagetotals_sum["CUST_QTY"]),2);

$smarty->assign("global_totalCAN_QTY_avg",GetData($avg,"CAN_QTY",""));


Could someone please point me in the right direction?
Thanks.

J
Jane 10/28/2008

Hi,
try to use this one:

$avg=format_number(array("CAN_QTY"=>$globaltotals_sum["CAN_QTY"] * 100 / $pagetotals_sum["CUST_QTY"]));

$smarty->assign("global_totalCAN_QTY_avg",GetData($avg,"CAN_QTY",""));