Search code examples
perlcatalyst

Round or ceil function in Template Toolkit


I need a value to be rounded in the Perl's Template Toolkit. But I am not able to use ceil().

[%interestRate = ceil(mortgage.interest_rate / 100)%]

The answer shows a null value.


Solution

  • I think the syntax to provide ceil is

    $c->stash->{ceil} = sub { ceil($_[0]) };
    
    [% c.ceil(c.mortgage.interest_rate / 100) %]
    

    But its usually better to do your calculations outside of templates.

    $c->stash->{mortgagetInterestRate} = ...;