Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round or ceil function in Template Toolkit

Tags:

perl

catalyst

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.

like image 610
Jitesh Avatar asked Nov 30 '22 02:11

Jitesh


2 Answers

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.

http://www.template-toolkit.org/docs/manual/Directives.html

like image 52
Zet Avatar answered Dec 05 '22 04:12

Zet


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
like image 31
Slaven Rezic Avatar answered Dec 05 '22 06:12

Slaven Rezic