Are there any conversion issues I should know when
converting a real into a float ?
Thanks
JHi
A real and a float are the same data type, just different names. Both are
approximate and can not represent the exact value.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Blond Moment" <anonymous@.discussions.microsoft.com> wrote in message
news:14c101c50452$95db8c30$a601280a@.phx.gbl...
> Are there any conversion issues I should know when
> converting a real into a float ?
> Thanks
> J|||Thanks Mike, your a sweetie.
>--Original Message--
>Hi
>A real and a float are the same data type, just different
names. Both are
>approximate and can not represent the exact value.
>Regards
>--
>Mike Epprecht, Microsoft SQL Server MVP
>Zurich, Switzerland
>IM: mike@.epprecht.net
>MVP Program: http://www.microsoft.com/mvp
>Blog: http://www.msmvps.com/epprecht/
>"Blond Moment" <anonymous@.discussions.microsoft.com>
wrote in message
>news:14c101c50452$95db8c30$a601280a@.phx.gbl...
>
>.
>|||To add to Mike's response, note that you may end up with different values
when converting between float and real data types when using the a float
precistion of 25 or greater. The default float precistion is 53:
DECLARE @.MyReal real
DECLARE @.MyFloat float
SET @.MyReal = 1.06
SET @.MyFloat = 1.06
SELECT @.MyReal AS MyReal, @.MyFloat AS MyFloat
SET @.MyFloat = @.MyReal
SELECT @.MyReal AS MyReal, @.MyFloat AS MyFloat
SET @.MyFloat = 1.06
SET @.MyReal = @.MyFloat
SELECT @.MyReal AS MyReal, @.MyFloat AS MyFloat
Hope this helps.
Dan Guzman
SQL Server MVP
"Blond Moment" <anonymous@.discussions.microsoft.com> wrote in message
news:14c101c50452$95db8c30$a601280a@.phx.gbl...
> Are there any conversion issues I should know when
> converting a real into a float ?
> Thanks
> J|||Mike,
Real and float are not the same data type, though they are in
the same data type family. The capabilities of the real and
float types in SQL Server derive from the internal format
used for their representation: real stores floating point values
according to the 4-byte IEEE standard, and float uses the
8-byte IEEE format.
Both real and float represent values exactly, but the reason they
are called "approximate" data types is that the exact values they
store do not match the decimal fixed-point values we use in the
familiar base-10 number system. Real and float store values exactly
in base-2 representation, so for example both real and float can store
11.5625 (or 11 9/16) exactly, but neither can store the value 0.1
(or 1/10) exactly, and an assignment of 1/10 to a real or float will
result in a stored value near to, but not equal to, 1/10.
Floats can store a wider range and precision than reals, but
the IEEE 4-byte and 8-byte formats are designed in such a
way that every representable real can be represented exactly
as a float.
All that said, the bottom line is that if a real value is assigned
to a float, no loss of precision will occur. It is similar to assigning
a decimal(5,2) value to a decimal(10,4).
SQL Server's use of "exact" and "approximate" to describe
decimal and float/real types is misleading, in my opinion. Both
type families store exact values. The values a decimal type like
decimal(3,1) can store are evenly spaced base-10 fixed-precision
numbers (-99.9, -99.8, ..., 99.8, 99.9), wherease the values a
float can store are unevenly-spaced base-2 floating-precision
numbers of the form (mantissa) * 2^(exponent), for a set of
evenly-spaced (mantissa) values >= 1/2 and < 1 and all values
of (exponent) between -1023 and +1023 (omitting some details
about the representation of infinity, negative zero, and reduced-
precision "denormalized" values with absolute value less
than 2^(-1023)).
-- Steve Kass
-- Drew University
-- Ref: E46D858E-5EFC-44C0-9EEB-F97C291E1B0D
Mike Epprecht (SQL MVP) wrote:
>Hi
>A real and a float are the same data type, just different names. Both are
>approximate and can not represent the exact value.
>Regards
>--
>Mike Epprecht, Microsoft SQL Server MVP
>Zurich, Switzerland
>IM: mike@.epprecht.net
>MVP Program: http://www.microsoft.com/mvp
>Blog: http://www.msmvps.com/epprecht/
>"Blond Moment" <anonymous@.discussions.microsoft.com> wrote in message
>news:14c101c50452$95db8c30$a601280a@.phx.gbl...
>
>
>
Sunday, February 12, 2012
Converting Reals into Floats
Labels:
conversion,
converting,
database,
float,
floats,
microsoft,
mysql,
oracle,
real,
reals,
server,
sql,
whenconverting
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment