From: Kyle Bateman <kyle@actarg.com>
To: pgsql-sql@hub.org
Cc: secret@kearneydev.com
Subject: Re: [SQL] Type Conversion: int4 -> Money
Date: Fri, 10 Sep 1999 10:01:17 -0600
Message-ID: <37D92B4D.125D0F59@actarg.com> (raw)
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"
}
Attachments:kyle.vcf (text/x-vcard, 290B) download
begin:vcard
n:Bateman;Kyle
tel;fax:801-377-8096
tel;work:801-377-8033x101
x-mozilla-html:FALSE
url:www.actiontarget.com
org:Action Target Inc
adr:;;PO Box 636;Provo;UT;84603;US
version:2.1
email;internet:kyle@actiontarget.com
title:President
x-mozilla-cpt:;-15520
fn:Kyle Bateman
end:vcard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: kyle@actarg.com, pgsql-sql@hub.org, secret@kearneydev.com
Subject: Re: [SQL] Type Conversion: int4 -> Money
In-Reply-To: <37D92B4D.125D0F59@actarg.com>
References: <37D92B4D.125D0F59@actarg.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox