Float or Decimal?

Float or Decimal?

Post by Guillermo Casta?o » Wed, 26 Nov 2003 00:28:56



Hi, i want to know which is the preferred datatype for numeric fields.
Decimal or float? and why?

Are there any performance, acurate reasons to pick one of them?

thanks

 
 
 

Float or Decimal?

Post by Foo Man Che » Wed, 26 Nov 2003 00:33:46


Float does some weird rounding things... try these out:




Compared to these results:






Quote:> Hi, i want to know which is the preferred datatype for numeric fields.
> Decimal or float? and why?

> Are there any performance, acurate reasons to pick one of them?

> thanks


 
 
 

Float or Decimal?

Post by Ashis » Wed, 26 Nov 2003 01:04:30



> Float does some weird rounding things... try these out:




> Compared to these results:






>>Hi, i want to know which is the preferred datatype for numeric fields.
>>Decimal or float? and why?

>>Are there any performance, acurate reasons to pick one of them?

>>thanks

howcome




= 7.7000

but




= 8 ?

decimal + decimal = int ?

is decimal declaration having no decimal assigned to it by default ?

-ashish

 
 
 

Float or Decimal?

Post by Fabian Castr » Wed, 26 Nov 2003 01:39:51


Quote:>-----Original Message-----
>Hi, i want to know which is the preferred datatype for
numeric fields.
>Decimal or float? and why?

You should avoid float. At least working on visual basic I
have gotten decimals "alive" after the fith decimal
position. Even when I have set the field with an entire
number.

like update some column = 7
and when I read the equialent txtfield in a VB form it is
7.0000056.... etc.

bye fabianc.

Quote:

>Are there any performance, acurate reasons to pick one of
them?

>thanks
>.

 
 
 

Float or Decimal?

Post by Louis Davidso » Wed, 26 Nov 2003 05:42:48



doesn't have a decimal point either.  The default scale is 0, which looks
like an integer.

--
----------------------------------------------------------------------------
-----------

Compass Technology Management

Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266

Note: Please reply to the newsgroups only unless you are
interested in consulting services.  All other replies will be ignored :)



> > Float does some weird rounding things... try these out:




> > Compared to these results:






> >>Hi, i want to know which is the preferred datatype for numeric fields.
> >>Decimal or float? and why?

> >>Are there any performance, acurate reasons to pick one of them?

> >>thanks

> howcome




> = 7.7000

> but




> = 8 ?

> decimal + decimal = int ?

> is decimal declaration having no decimal assigned to it by default ?

> -ashish

 
 
 

Float or Decimal?

Post by Louis Davidso » Wed, 26 Nov 2003 05:48:35


What are you doing with them?  Floating point numbers are generally used for
calculations, measurements, etc, where a small error is allowable.  They are
faster than numerics, because floating points are dealt with by the FPU
directly, while numerics are database specific (integers are manipulated
with registers, so they are even faster) and use CPU to do math.  However,
you wouldn't want to store monetary values in them (use money datatype if
possible, as it is based on integer datatypes, and does not lose any
precision.

--
----------------------------------------------------------------------------
-----------

Compass Technology Management

Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266

Note: Please reply to the newsgroups only unless you are
interested in consulting services.  All other replies will be ignored :)



Quote:> Hi, i want to know which is the preferred datatype for numeric fields.
> Decimal or float? and why?

> Are there any performance, acurate reasons to pick one of them?

> thanks

 
 
 

Float or Decimal?

Post by Steve Kas » Wed, 26 Nov 2003 06:41:06


Louis,

  Money doesn't lose precision ... *if* it is only used for addition,
subtraction, and
multiplication by integers.

  Unfortunately, the careful rules by which decimal calculations are
designed
to do their best to hold both good precision and scale are out the
window when
it comes to money.

  Suppose you pay $2.57 per 10,000 widgets.  How much are you paying for
each?

  select $2.57/10000

Oh-oh.  Money has it's place, but it can also lead to very bad results.  
You might
argue that 0.000257 isn't supposed to be well-represented as money,
which only
has 4 decimal places of precision, but there are plenty of other money-type
problems - for reasons I can't understand, money/money is money, not pure
number, and the precision can't be handled correctly.  You might want to
divide monetary values to figure out, say, what fraction $1.23 is of a
$2137 bill:

  select $1.23/$2137

It's off by a lot - in my opinion, because the answer is wrongly typed
as money.
So beware.

-- Steve Kass
-- Drew University
-- Ref: D3F842EE-4910-40CA-A345-CAF0A63A9CE8


>What are you doing with them?  Floating point numbers are generally used for
>calculations, measurements, etc, where a small error is allowable.  They are
>faster than numerics, because floating points are dealt with by the FPU
>directly, while numerics are database specific (integers are manipulated
>with registers, so they are even faster) and use CPU to do math.  However,
>you wouldn't want to store monetary values in them (use money datatype if
>possible, as it is based on integer datatypes, and does not lose any
>precision.

 
 
 

1. Converting float to decimal

We are considering changing some numberic data types in Sybase from float to
decimal (which is new with System 10).  Is this recommended and has anyone
had any problems using the decimal data type in Sybase?

2. Can't do a script right. Help!

3. Float to decimal

4. Master database backup

5. Float or Decimal

6. Accessing a Lotus Notes 4.6 database using HTML/Javascript?

7. Converting to float or decimal

8. Browse as a row or Column?

9. Converting FLOAT to DECIMAL

10. float vs decimal

11. Float and Decimal Type

12. What's different between Float and Decimal datatype in Sql server

13. Floats and decimals type