I've been looking at the Decimal and Float data types. When it come to
storing a value such as 10.55%, 25.00% or 99.99%, which is the most
appropriate?I recommend decimal instead of float if you need exact decimal values .
Float and real follow the IEEE 754 specification on approximate numeric data
types and cannot store all decimal values accurately. See "approximate data
types" in the the Books Online for details.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Greg" <AccessVBAnet@.newsgroups.nospam> wrote in message
news:43D7259F-B754-4753-AB5B-85CEABDA319F@.microsoft.com...
> I've been looking at the Decimal and Float data types. When it come to
> storing a value such as 10.55%, 25.00% or 99.99%, which is the most
> appropriate?|||So in this case, 10.55%, 100.99%, etc. I would use Decimal(5.2), Precision =5, Scale = 2?
Thanks
"Dan Guzman" wrote:
> I recommend decimal instead of float if you need exact decimal values .
> Float and real follow the IEEE 754 specification on approximate numeric data
> types and cannot store all decimal values accurately. See "approximate data
> types" in the the Books Online for details.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Greg" <AccessVBAnet@.newsgroups.nospam> wrote in message
> news:43D7259F-B754-4753-AB5B-85CEABDA319F@.microsoft.com...
> > I've been looking at the Decimal and Float data types. When it come to
> > storing a value such as 10.55%, 25.00% or 99.99%, which is the most
> > appropriate?
>|||> So in this case, 10.55%, 100.99%, etc. I would use Decimal(5.2), Precision
> => 5, Scale = 2?
It depends on the range you need to store. Decimal(5,2) is sufficient to
store -999.99 through +999.99.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Greg" <AccessVBAnet@.newsgroups.nospam> wrote in message
news:D535955C-A6AF-4C3B-B689-22BEC7D84A44@.microsoft.com...
> So in this case, 10.55%, 100.99%, etc. I would use Decimal(5.2), Precision
> => 5, Scale = 2?
> Thanks
>
> "Dan Guzman" wrote:
>> I recommend decimal instead of float if you need exact decimal values .
>> Float and real follow the IEEE 754 specification on approximate numeric
>> data
>> types and cannot store all decimal values accurately. See "approximate
>> data
>> types" in the the Books Online for details.
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> "Greg" <AccessVBAnet@.newsgroups.nospam> wrote in message
>> news:43D7259F-B754-4753-AB5B-85CEABDA319F@.microsoft.com...
>> > I've been looking at the Decimal and Float data types. When it come to
>> > storing a value such as 10.55%, 25.00% or 99.99%, which is the most
>> > appropriate?|||I actually had this doubt as well for a long time. The number of bytes that
each datatype use does not make much difference (check BOL). So when I
require exactness and it comes to numbers with not many decimal positions
and depending on the operation (which in some cases can make the exact
numeric data types behave not so exact), I definitely prefer decimal data
type. In some other cases the float can be useful.
I think you can read Hugo Kornelis' article 'So-called "exact" numerics are
not at all exact!' on SQLblog.com, which helped me a lot to understand
better when to use each datatype.
Alan Ferrandiz Langley [MCT]
"Greg" <AccessVBAnet@.newsgroups.nospam> escribió en el mensaje
news:43D7259F-B754-4753-AB5B-85CEABDA319F@.microsoft.com...
> I've been looking at the Decimal and Float data types. When it come to
> storing a value such as 10.55%, 25.00% or 99.99%, which is the most
> appropriate?
>|||On Mon, 28 Jan 2008 01:47:39 -0500, Alan Ferrandiz Langley [MCT] wrote:
(snip)
>I think you can read Hugo Kornelis' article 'So-called "exact" numerics are
>not at all exact!' on SQLblog.com, which helped me a lot to understand
>better when to use each datatype.
Hi Alan,
Thanks for the free plug, and the nice words. For anyone interested,
here is a direct link to that article:
http://sqlblog.com/blogs/hugo_kornelis/archive/2007/10/17/so-called-exact-numerics-are-not-at-all-exact.aspx
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment