Author 
Topic 

aprichard
Yak Posting Veteran
India
62 Posts 
Posted  04/16/2009 : 09:16:00

Can any one of you explain drawback of float type. 

SwePeso
Patron Saint of Lost Yaks
Sweden
30421 Posts 
Posted  04/16/2009 : 09:33:31

It's inprecise for decimals. Integer part will work ok. It uses a binary storing algorithm due to the IEEE754 standard it uses.
E 12°55'05.63" N 56°04'39.26" 


SwePeso
Patron Saint of Lost Yaks
Sweden
30421 Posts 
Posted  04/16/2009 : 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.22044604925031E16) and all possible values to store are multiples of this smallest possible value.
E 12°55'05.63" N 56°04'39.26" 
Edited by  SwePeso on 04/16/2009 09:51:29 


Transact Charlie
Flowing Fount of Yak Knowledge
United Kingdom
3451 Posts 
Posted  04/16/2009 : 10:50:57

[everything Peso said] = rounding errors!
compare FLOAT and DECIMAL / NUMERIC in books on line
Charlie =============================================================== Msg 3903, Level 16, State 1, Line 1736 The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION 


SwePeso
Patron Saint of Lost Yaks
Sweden
30421 Posts 
Posted  06/28/2013 : 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
United Kingdom
160 Posts 
Posted  06/28/2013 : 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. 
Edited by  michael.appleton on 06/28/2013 05:22:53 



Topic 
