1. common.php
    2. /**
    3. * 计算百分比
    4. *
    5. * @param [type] $number 分子
    6. * @param [type] $total 分母
    7. * @return void
    8. * @Description
    9. * @example
    10. * @author luxiaojun
    11. * @since
    12. */
    13. function calculatePercent($number, $total)
    14. {
    15. if (0 == $number || 0 == $total) {
    16. return '0%';
    17. }
    18. if ($number >= $total) {
    19. return '100%';
    20. }
    21. return (int)($number / $total * 100) . '%';
    22. }

    模板调用

    {$number|calculatePercent=20}