in reply to Template Toolkit Formatting Data Question (sprintf and commafy)
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Template Toolkit Formatting Data Question (sprintf and commafy)
by Tyraziel (Novice) on Jul 13, 2005 at 15:33 UTC | |
|
Re^2: Template Toolkit Formatting Data Question (sprintf and commafy)
by Anonymous Monk on Dec 09, 2011 at 08:25 UTC |