I have this:
# add commas to numbers. 2.17 in perl cookbook
$Template::Stash::SCALAR_OPS->{commify} =
sub {
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}
Usage:
[% number.commify %]
---
Rodney Broom
----- Original Message -----
From: "Felipe Gasper (cPanel)" <[email protected]>
To: <[email protected]>
Sent: Friday, April 23, 2010 10:09
Subject: [Templates] add thousands separator to number
> Hey all,
>
> What is the best way in TT to add thousands separators to numbers, e.g.
> 1234567 -> '1,234,567'?
>
> -FG
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
>
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates