Herouth Maoz wrote:
> testing=> select num, num * '1'::money from test1;
> num|?column?
> ------+-----------
> 2|$2.00
> 4|$4.00
> -14|($14.00)
> 38|$38.00
> 199|$199.00
> 100399|$100,399.00
> (6 rows)
>
> Is that what you wanted?
>
> Herouth
>
> Perl... I ended up writing my own formatting function... It has one
that
> does ####.## however not one that'll do the nice 123,456.33 ... :) Do
you know
> if there are any public modules that do such things?
I use this in tcl to format a dollar amount. Mine runs in the frontend,
but it could easily be made into a pltcl function:
#format for dollars, including commas
#------------------------------------------
#val: the value as input by the user
proc comma_dollar {val} {
if {$val == {}} {set val 0.00}
if {$val < 0} {set sign {-}; set val [expr -$val]} else {set sign
{}}
set val [format {%#.2f} $val]
lassign [split $val .] dol cents
set cdol {}
for {set len [string length $dol]} {$len > 0} {incr len -3} {
if {$cdol == {}} {
set cdol "[string range $dol [expr $len - 3] [expr $len -
1]]"
} else {
set cdol "[string range $dol [expr $len - 3] [expr $len -
1]] $cdol
}
}
return "$sign[join $cdol ,].$cents"
}