Re: [SQL] Type Conversion: int4 -> Money

From: Kyle Bateman <kyle(at)actarg(dot)com>
To: pgsql-sql(at)hub(dot)org
Cc: secret(at)kearneydev(dot)com
Subject: Re: [SQL] Type Conversion: int4 -> Money
Date: 1999-09-10 16:01:17
Message-ID: 37D92B4D.125D0F59@actarg.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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"
}

Attachment Content-Type Size
kyle.vcf text/x-vcard 291 bytes

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-09-10 19:07:18 Re: [GENERAL][SQL] Getting multiple field unique index to distinguish NULLs.
Previous Message Jackson, DeJuan 1999-09-10 15:44:38 RE: [GENERAL][SQL] Getting multiple field unique index to disting uish NULLs.