You are less likely to run into the issue when there are no calculations
involved, but I wouldn't guarantee it.  If you want to be on the safe side
when using floating pont, do not check for EQUAL to, but within a range (+/-
some small delta).  As a rule of thumb, avoid floating point except for
situations where you really need to represent very small fractions or
extremely large numbers with less than 100% accuracy, or for real number
math application (engineering, science).

Regards,
Tore.

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


> OH THANK YOU SO MUCH for that info!!! My first little database I created
> today in mySql, I used that floating stuff on two columns, but they are
only
> to hold the height and width of my embroidery designs ... so I want to be
> able to enter 3.25 (as in inches) and 10.12 etc... I'm not planning on
> calculating with the fields, they're really just there for people to view
> and search on  .... if their embroidery machine can't do a design bigger
> than 4" x 4" they can search and make sure those width and height columns
> don't exceed 4".
>
> So is my usage of float ok?
>
> Renee :)
>
> -----Original Message-----
> From: Tore [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 21, 2003 5:29 PM
> To: mysql
> Subject: Re: decimal type
>
>
> 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
>
>
>
>
>


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