Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
aprichard
Yak Posting Veteran
62 Posts |
Posted - 2009-04-16 : 09:16:00
|
Can any one of you explain drawback of float type. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-16 : 09:33:31
|
It's inprecise for decimals. Integer part will work ok.It uses a binary storing algorithm due to the IEEE-754 standard it uses. E 12°55'05.63"N 56°04'39.26" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-16 : 09:45:11
|
The reason is that the decimal part must be represented in the way(bit1 / 2^1) + (bit2 / 2^2) + (bit3 / 2^3) + (bit4 / 2^4) + ...(bit1 / 2) + (bit2 / 4) + (bit3 / 8) + (bit4 / 16) + ...If you sum all these combinations to infinity the sum is exactly 1, which means in theory all possible decimal values can be used and represented.However IEEE754 says only 52 bits can be used for decimals. So smallest value is 1 / 2^52 (roughly 2.22044604925031E-16)and all possible values to store are multiples of this smallest possible value. E 12°55'05.63"N 56°04'39.26" |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-04-16 : 10:50:57
|
[everything Peso said] = rounding errors!compare FLOAT and DECIMAL / NUMERIC in books on lineCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-06-28 : 04:45:38
|
And what is also important, if you restore your database containing a FLOAT, the value might differ if the new server has another kind of processor. N 56°04'39.26"E 12°55'05.63" |
|
|
michael.appleton
Posting Yak Master
160 Posts |
Posted - 2013-06-28 : 05:21:59
|
I think an easy to imagine a floating point number is usually a very good approximation of a number. It you need something to be exact, don't use a floating point number. |
|
|
|
|
|