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} = ...;
Question
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 3
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} = ...;
OTHER TIPS
Maybe you need division directive:
[% 15 / 6 %] -> 2.5
[% 15 div 6 %] -> 2
[% 15 mod 6 %] -> 3
The div operator returns the integer result of division. Both % and mod return the modulus (i.e. remainder) of division.
If you prefer a CPAN module, then look into Template::Plugin::POSIX
. This module provides amongst others the ceil
and floor
functions:
[% USE POSIX -%]
[% POSIX.ceil(0.5) %]
[% POSIX.floor(0.5) %]
Output:
1
0
If last digit do not matter:
[% number FILTER format("%.2f"); %]