I'm a bit confused as to what your problem is. Did you try something like this?
This command line script simply creates a custom filter to commify, and uses the built in format filter to truncate the extraneous decimal numbers. This way, you can use number as it is, or chain it to get a combination of commify and sprintf.use strict; use warnings; use Template; my $tt = Template->new({ FILTERS => { commify => \&commify, }, }); $tt->process(\*DATA, { number => 420000.2527 }) || die $tt->error(); # Perl Cookbook recipe 2.17 sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } __DATA__ [% number | format('%.02f') | commify %]
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: Template Toolkit Formatting Data Question (sprintf and commafy)
by jeffa
in thread Template Toolkit Formatting Data Question (sprintf and commafy)
by Tyraziel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |