This topic is locked

function round() - I need help!

11/10/2011 11:18:59 AM
PHPRunner General questions
S
sumo author

Hi there,
the following code in a report project puts out an average value with loads of decimals, but I only want 2 decimals to show up.
<P align=center>&nbsp; {$groupJahr_totalAge_avg} </P></TD>
I know there is this wonderful function round(), yet I can't find the right syntax to include it in the above line.
Would somebody please help me? I know there are many of you who know the answer to this simple question!
Thanks!
sumo

C
cgphp 11/10/2011

In the "Before display" event of the Report enter this code:

$xt->assign("groupJahr_totalAge_avg", round($xt->getvar("groupJahr_totalAge_avg")));
S
sumo author 11/10/2011



In the "Before display" event of the Report enter this code:

$xt->assign("groupJahr_totalAge_avg", round($xt->getvar("groupJahr_totalAge_avg")));



Hi Christian and thanks so much for answering so quickly.

Your code gives me some hints on the syntax of functions used in PHPRunner.
But this one doesn't work for me. It doesn't lead to broken pages or something like that, just to a plain 0(=ZERO) in the field, where a 45.15 (rather 45,15) or so should appear.
Now, the situation is:

  • I want to round average values that are calculated in a report page IN that report. So I guess those calculated values that I want to round are not yet there on the event "Before display"???
  • In that report I have several averages. Some have the "," for decimals, others the "." (and I actually don't know why those "." appear there instead of the ","). The ones with the "," for decimals are absolutely fine in displaying 2 decimals. The ones with the "." make trouble.
    Do you have any idea???

C
cgphp 11/11/2011

Remove the code from the "Before display" event and in the Visual editor set the Age field as custom and enter this code:

$value = number_format(round($value,2),2,'.','');



Make sure the type of the Age field in the database is set as float(10,5)