Gossamer Forum
Home : Products : DBMan SQL : Discussion :

comma between digits

Quote Reply
comma between digits
Seasons Greetings
got a quick question:
when doing a simple record count, what code is required to include a comma between every 3, 6 or 9th whole number?
ie 1,000

code below: thanks Rob

$query = qq!

SELECT count(*)
FROM $db_table

$sth = $dbh->prepare ($query) or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
($count) = $sth->fetchrow_array();
Quote Reply
Re: [robert1234] comma between digits In reply to
Try something like:

$count = $sth->fetchrow_array();

1 while $count =~ s/^([-+]?\d+)(\d{3})/$1,$2/;

Then print $count wherever you want it.