pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedFloat / Numeric ?
2+ messages / 2 participants
[nested] [flat]
* Float / Numeric ?
@ 2002-07-22 00:06 Rudi Starcevic <rudi@oasis.net.au>
0 siblings, 1 reply; 2+ messages in thread
From: Rudi Starcevic @ 2002-07-22 00:06 UTC (permalink / raw)
To: pgsql-sql
Hi Folks,
I have an ecommerce application I'm writing and I'm not sure / undecided
on a
particular way to store shipping rates in PostgreSQL
In this application a user may set the shipping rate per item.
So I have 3 fields - local,state and international.
A forth field, shipping_type (varchar), holds a value 'dollars' or
'percent'.
My twisted logic says a user may say this item has 10 perent shipping to
add or 10 dollars to add.
This means the shipping rate my be either dollars or percent and can be
set on a per item basis.
For the 3 fields I'm not sure which is best to use - Float or Numeric ?
My application language is ColdFusion and PHP.
I'd like to ask which data type would be the better choice.
At this stage I'm using Float to represent a value that may be either
dollars or percent.
Perhaps this technique, using a varchar as a type of switch
(shipping_type) , is incorrect / silly / stupid / not robust enough or
just plain wrong.
Do you think this is OK and if so which would you use - Floast or Numeric ?
Thanks for your time.
Cheers
Rudi.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Float / Numeric ?
@ 2002-07-22 17:13 Jan Wieck <JanWieck@Yahoo.com>
parent: Rudi Starcevic <rudi@oasis.net.au>
0 siblings, 0 replies; 2+ messages in thread
From: Jan Wieck @ 2002-07-22 17:13 UTC (permalink / raw)
To: Rudi Starcevic <rudi@oasis.net.au>; +Cc: pgsql-sql
Rudi Starcevic wrote:
>
> Hi Folks,
>
> I have an ecommerce application I'm writing and I'm not sure / undecided
> on a
> particular way to store shipping rates in PostgreSQL
>
> In this application a user may set the shipping rate per item.
>
> So I have 3 fields - local,state and international.
> A forth field, shipping_type (varchar), holds a value 'dollars' or
> 'percent'.
>
> My twisted logic says a user may say this item has 10 perent shipping to
> add or 10 dollars to add.
> This means the shipping rate my be either dollars or percent and can be
> set on a per item basis.
>
> For the 3 fields I'm not sure which is best to use - Float or Numeric ?
>
> My application language is ColdFusion and PHP.
>
> I'd like to ask which data type would be the better choice.
> At this stage I'm using Float to represent a value that may be either
> dollars or percent.
>
> Perhaps this technique, using a varchar as a type of switch
> (shipping_type) , is incorrect / silly / stupid / not robust enough or
> just plain wrong.
>
> Do you think this is OK and if so which would you use - Floast or Numeric ?
> Thanks for your time.
You can have separate fields for percent or fixed amount. With a zero
default (not NULL) the calculation is still simple enough bacause adding
zero or a multiple of it usually does not affect the result very much.
For the data type I allways advise NUMERIC for anything that deals with
money. There are legal issues with money and floating point in some
countries around the world (especially the pickier ones who love to
overengineer everything like Germany).
And make sure that the application doesn't work with floating point
either. PHP can be built with bcmath support, which does arbitrary
precision like our NUMERIC type.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-07-22 17:13 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-22 00:06 Float / Numeric ? Rudi Starcevic <rudi@oasis.net.au>
2002-07-22 17:13 ` Jan Wieck <JanWieck@Yahoo.com>
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