Re: [Templates] rounding numbers
[prev]
[thread]
[next]
[Date index for 2005/02/17]
>>>>> "Dave" == Dave Cross <dave@xxxx.xxx.xx> writes:
Dave> On Thu, Feb 17, 2005 at 03:00:09PM +0100, Matthias.Dillier@xxx.xx wrote:
>> templates-admin@xxxxxxxxxxxxxxxx.xxx wrote on 17.02.2005 11:38:44:
>>
>> > You can write a couple of simple macros to do it for you:
>> >
>> > [% MACRO ceiling(n)
>> > GET n + 1
>> > FILTER format("%d");
>> >
>> >
>> > MACRO floor(n)
>> > GET n
>> > FILTER format("%d");
>> > %]
>> >
>> > [% ceiling(1.5) %] # round up
>> > [% floor(1.5) %] # round down
>>
>> [% ceiling(2) %] # gives 3, rounded up to much.
>> Or do I misinterpret something here?
Dave> You can change the macro to add 0.5 instead of 1.
Dave> But then that'll probably fail on negative numbers or something
Dave> like that :(
Or on 1.4. That'll give a ceiling of 1. Still not right. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxx.xxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates