pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
function to format floats as money?
7+ messages / 4 participants
[nested] [flat]

* function to format floats as money?
@ 2001-04-17 14:30  Mark Stosberg <mark@summersault.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Mark Stosberg @ 2001-04-17 14:30 UTC (permalink / raw)
  To: pgsql-sql


Hello,

  I'm curious to know if there is a function available in Postgres 7.0.3
(or 7.1) that will format a float style number as "money". I understand
that the money type is going away in the future, so using a float type
that is sometimes formatted like money seems like a good alternative. So
ideally, I'm looking for a solution that won't go away when the money type
does. :) Thanks!

  -mark

http://mark.stosberg.com/




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: function to format floats as money?
@ 2001-04-17 15:27  Peter Eisentraut <peter_e@gmx.net>
  parent: Mark Stosberg <mark@summersault.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Peter Eisentraut @ 2001-04-17 15:27 UTC (permalink / raw)
  To: Mark Stosberg <mark@summersault.com>; +Cc: pgsql-sql

Mark Stosberg writes:

>   I'm curious to know if there is a function available in Postgres 7.0.3
> (or 7.1) that will format a float style number as "money". I understand
> that the money type is going away in the future, so using a float type
> that is sometimes formatted like money seems like a good alternative. So
> ideally, I'm looking for a solution that won't go away when the money type
> does. :) Thanks!

to_char() for formatting.

numeric for storage.

Using floats for monetary amounts is not only an extremely bad idea
because of the inexactness of storage and arithmetic, it might even be
illegal if you're using it for official purposes.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: function to format floats as money?
@ 2001-04-17 15:31  Mark Stosberg <mark@summersault.com>
  parent: Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 1 reply; 7+ messages in thread

From: Mark Stosberg @ 2001-04-17 15:31 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-sql

Peter Eisentraut wrote:
> 
> Mark Stosberg writes:
> 
> >   I'm curious to know if there is a function available in Postgres 7.0.3
> > (or 7.1) that will format a float style number as "money". I understand
> > that the money type is going away in the future, so using a float type
> > that is sometimes formatted like money seems like a good alternative. So
> > ideally, I'm looking for a solution that won't go away when the money type
> > does. :) Thanks!
> 
> to_char() for formatting.
> 
> numeric for storage.
> 
> Using floats for monetary amounts is not only an extremely bad idea
> because of the inexactness of storage and arithmetic, it might even be
> illegal if you're using it for official purposes.

Thanks Peter.

  So  if the money type is going away, and floats can be illegal, whats
the best way to store money? 

  -mark

personal website             }      Summersault Website Development
http://mark.stosberg.com/    {      http://www.summersault.com/



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: function to format floats as money?
@ 2001-04-17 17:41  Ross J. Reedstrom <reedstrm@rice.edu>
  parent: Mark Stosberg <mark@summersault.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Ross J. Reedstrom @ 2001-04-17 17:41 UTC (permalink / raw)
  To: Mark Stosberg <mark@summersault.com>; +Cc: pgsql-sql

On Tue, Apr 17, 2001 at 10:31:49AM -0500, Mark Stosberg wrote:
> Peter Eisentraut wrote:
> > 
> > Mark Stosberg writes:
> > 
> > >   I'm curious to know if there is a function available in Postgres 7.0.3
> > > (or 7.1) that will format a float style number as "money". I understand
> > > that the money type is going away in the future, so using a float type
> > > that is sometimes formatted like money seems like a good alternative. So
> > > ideally, I'm looking for a solution that won't go away when the money type
> > > does. :) Thanks!
> > 
> > to_char() for formatting.
> > 
> > numeric for storage.
> > 
> > Using floats for monetary amounts is not only an extremely bad idea
> > because of the inexactness of storage and arithmetic, it might even be
> > illegal if you're using it for official purposes.
> 
> Thanks Peter.
> 
>   So  if the money type is going away, and floats can be illegal, whats
> the best way to store money? 

Why, in the bank, or under your mattress, depending on your level of
paranoia, of course. But seriously, numeric(10,2) (or whatever precision
and scale is correct for your application) is the standard answer.

 Ross



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: function to format floats as money?
@ 2001-04-17 18:52  John Hasler <john@dhh.gt.org>
  parent: Ross J. Reedstrom <reedstrm@rice.edu>
  0 siblings, 1 reply; 7+ messages in thread

From: John Hasler @ 2001-04-17 18:52 UTC (permalink / raw)
  To: pgsql-sql

Ross writes:
> But seriously, numeric(10,2) (or whatever precision and scale is correct
> for your application) is the standard answer.

Floats are fine for money as long as you only add and subtract and don't
deal in amounts that won't fit in the mantissa.
-- 
John Hasler
john@dhh.gt.org (John Hasler)
Dancing Horse Hill
Elmwood, WI



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: function to format floats as money?
@ 2001-04-17 19:59  Ross J. Reedstrom <reedstrm@rice.edu>
  parent: John Hasler <john@dhh.gt.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Ross J. Reedstrom @ 2001-04-17 19:59 UTC (permalink / raw)
  To: John Hasler <john@dhh.gt.org>; +Cc: pgsql-sql

On Tue, Apr 17, 2001 at 01:52:16PM -0500, John Hasler wrote:
> Ross writes:
> > But seriously, numeric(10,2) (or whatever precision and scale is correct
> > for your application) is the standard answer.
> 
> Floats are fine for money as long as you only add and subtract and don't
> deal in amounts that won't fit in the mantissa.

Or you're writing software in Germany (all of the EU now?) that _might_
get used in an offical capacity.

Ross



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: function to format floats as money?
@ 2001-04-17 20:32  John Hasler <john@dhh.gt.org>
  parent: Ross J. Reedstrom <reedstrm@rice.edu>
  0 siblings, 0 replies; 7+ messages in thread

From: John Hasler @ 2001-04-17 20:32 UTC (permalink / raw)
  To: pgsql-sql

I wrote:
> Floats are fine for money as long as you only add and subtract and don't
> deal in amounts that won't fit in the mantissa.

Ross writes:
> Or you're writing software in Germany (all of the EU now?) that _might_ get
> used in an offical capacity.

I was referring to what actually works, not to what might or might not meet
with the approval of some officialdom or other.  The two seldom bear any
discernible relationship.
-- 
John Hasler
john@dhh.gt.org (John Hasler)
Dancing Horse Hill
Elmwood, WI



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2001-04-17 20:32 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-17 14:30 function to format floats as money? Mark Stosberg <mark@summersault.com>
2001-04-17 15:27 ` Peter Eisentraut <peter_e@gmx.net>
2001-04-17 15:31   ` Mark Stosberg <mark@summersault.com>
2001-04-17 17:41     ` Ross J. Reedstrom <reedstrm@rice.edu>
2001-04-17 18:52       ` John Hasler <john@dhh.gt.org>
2001-04-17 19:59         ` Ross J. Reedstrom <reedstrm@rice.edu>
2001-04-17 20:32           ` John Hasler <john@dhh.gt.org>

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