Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Displaying commas in number fields

Quote Reply
Displaying commas in number fields
Is there any way to get DBManSQL to display commas in a price field?

A price of $500,000 is much easier to read than $500000.

If it's possible what would be required?



Thanks
Quote Reply
Re: [BrianC] Displaying commas in number fields In reply to
Try create a global template called 'format_usd':

sub {
my ($name) = shift;
my $tags = GT::Template->tags;
my $value = $tags->{$name};
my $dol_str = reverse sprintf( "%.2f", $value );
$dol_str =~ s/(\d\d\d)/$1,/g;
$dol_str =~ s/,$//;
$dol_str = $dol_str . "\$";
return scalar reverse $dol_str;
}

Now you can use <%format_usd('variable_name')%> in the template

TheStone.

B.

Last edited by:

TheStone: Sep 18, 2002, 5:35 PM
Quote Reply
Re: [TheStone] Displaying commas in number fields In reply to
Works perfectly!



Thanks
Quote Reply
Re: [BrianC] Displaying commas in number fields In reply to
Hello

How can I format the results for Money in this way

R$ 0.000.000,00

at each group of 3 numbers show a point?

And how the regex would be?

Thanks

Fábio
Quote Reply
Re: [assombracao] Displaying commas in number fields In reply to
try to change the global a little bit and the regex could be like below :

Code:
sub {
my ($name) = shift;
my $tags = GT::Template->tags;
my $dol_str = sprintf( "%.2f", $tags->{$name} );
$dol_str =~ s/\.(\d{2})$/,$1/;
1 while $dol_str =~ s/(\d)(\d{3})\b/$1.$2/;
return 'R$ '.$dol_str;
}


Cheers,
Jean
Gossamer Threads, Inc.