Floating point should not be used for money or for representing any other
discrete numeric values.  You will get in trouble because the floating point
value can deviate from the discrete value it is intended to represent.
Floating point introduces (small) rounding errors.

Say an account has a balance of $265.50 and the user wants to withdraw the
entire amount, if your code checks that the withdrawal amount is less or
equal to the balance, it MAY not allow the withdrawal.  Depending on how the
original value was established, you could see something like:

In the table AccountBalances

AccountID = 999
Balance = 265.499999967    (value for illustration purposes only)

Application screen shows two decimals:
Balance = $265.50

Customer withdrawal amount: $265.50

Query (or application logic with floating point values) that includes a
balance check:

UPDATE AccountBalances
SET Balance = Balance - 265.50
WHERE AccountID = 999
AND Balance >= 265.50

This will affect 0 rows, which your code is smart enough to determine
meaning "insufficient funds".

So, the moral of this story is to use fixed precision numerical values to
store information such as money... :->

HTH,
Tore.


----- Original Message -----
From: "Stitchin'" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, February 21, 2003 5:00 PM
Subject: RE: decimal type


> Why couldn't you use float(10,2) ... just an example ... where the first
> number in the parentheses is the total characters for the number and the
> second number represents how many of those are right of the decimal
point?)
>
> I'm a TOTAL newbie to this stuff, I just set up my first mySql database
> today ... so I hope I'm not too far off base.
>
> Renee
> Stitchin' Up A Storm
>
> -----Original Message-----
> From: Bryan Koschmann - GKT [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 21, 2003 4:01 PM
> To: gerald_clark
> Cc: [EMAIL PROTECTED]
> Subject: Re: decimal type
>
>
> My Apologies,
>
> table name is pricelist with 2 colums:
> create table pricelist (product varchar(45), cost dec);
>
>
> then
>
> load data infile "/home/omni/OmniPrice.csv" into table pricelist fields
> terminated by ',';
>
> the datafile looks like this
>
> Jaton Modem,15.5
> Teac Floppy,7.5
> Celeron 1.7,54.5
> Logitech KB,11
>
>
> but a query returns this:
>
> mysql> select * from pricelist;
> +-------------+------+
> | product     | cost |
> +-------------+------+
> | Jaton Modem |   15 |
> | Teac Floppy |    7 |
> | Celeron 1.7 |   54 |
> | Logitech KB |   11 |
> +-------------+------+
> 4 rows in set (0.00 sec)
>
>
> I read the docs on the decimal type, but I dont quite understand it.
>
> Thanks,
>
> Bryan
>
>
> On Fri, 21 Feb 2003, gerald_clark wrote:
>
> |Show us.
> |We have no idea how you defined your tables,
> |loaded your data, or structured your query.
> |
> |Bryan Koschmann - GKT wrote:
> |
>
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
>
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to