Using the ROUND function in Perl

I was using the ROUND function within some Perl Script as follows ...

[%Begin Unverified Perl 

 my $i=1;
 my $MD1Total=0;
 my $MD1Average=0;

 for($i=1; $i<=30; $i++)
  {
   $MD1Total=$MD1Total+VALUE("MD1_r1_c".$i)+VALUE("MD1_r2_c".$i);
  }

 $MD1Average=$MD1Total/60;
 
 SETVALUE("MD1AverageRating",ROUND($MD1Average,2));
 
End Unverified%]


I have 60 data points (saved in MD1_r1_c1 to MD1_r1_c30 and MD1_r2_c1 to MD1_r2_c30). It's a simple average calculation across the 60 data points that I am seeking. No problems there. It works fine.

To put the icing on the cake, I wanted to round the average to 2 decimal places (always). It almost works every time. I noticed if the average was 41.40, it only saved 41.4, and not 41.40. I suspect an average of 51.00 would only appear as 51?

Was hoping to find a neat solution where my average calculation always provided me with the nearest 2 decimal places.

Resolved
18 replies