简体   繁体   中英

Round the summary row in phpgrid

I have a grid with a summaryrow which shows the averages of the group like this:

$dg->set_group_properties('year');
$dg->set_group_summary('amount','avg'); 

The output will add a summary row with the average purchase amount per customer for a given year (group).

Now I want to round the average in the summary row to 1 digit (ie 467.075 should be 467.1 ), but I don't know how.

This helped me: https://phpgrid.uservoice.com/knowledgebase/articles/215864-fix-group-sum-floating-decimal-issue

<?php 
... 
$dg->set_group_summary('amount','###mysum###'); 
... 
?>

<script> 
function mysum(val, name, record) 
{ 
// this will round sum to 2 decimal 
return parseFloat(parseFloat(val||0) + parseFloat((record[name]||0))).toFixed(2); 
} 
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM