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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 What is a Float?

Author  Topic 

jp2code
Posting Yak Master

175 Posts

Posted - 2009-02-11 : 22:05:39
I've got a data column I'm trying to read that is listed as a float whenever I look at the table design in Enterprise Manager.

However, after I read this column, if I attempt to assign it to a float or integer value, an exception is thrown that says type mismatch.

What is a float?


Avoid Sears Home Improvement

raky
Aged Yak Warrior

767 Posts

Posted - 2009-02-11 : 23:21:06


see this

http://www.databasejournal.com/features/mssql/article.php/1442341/SQL-Server-2000-Datatypes.htm#part_5
Go to Top of Page

jp2code
Posting Yak Master

175 Posts

Posted - 2009-02-12 : 09:20:20
Ok, then let me rephrase:

How do I assign it to a value in my Visual Studio project? It will not assign to a float, decimal, or integer value.


Avoid Sears Home Improvement
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 09:31:30
Try Double for Float.

A float is the number which in the format

2^n + 2^(n-1) ... + 2^0 (integer part)
2^(-1) + 2^(-2) (decimal part)

can represent the number you want to store.
So when using float, you get an exact representation for all integer, but when dealing with decimals, you get the nearest number which can be expressed in 2^(-1) + 2^(-2) + 2^(-n) + 2^(-n - 1) etc

That's why FLOAT are inprecise for most decimal values.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-12 : 09:35:34
quote:
Originally posted by jp2code

Ok, then let me rephrase:

How do I assign it to a value in my Visual Studio project? It will not assign to a float, decimal, or integer value.


Avoid Sears Home Improvement


how are you currently trying to assign value?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 09:49:52
This is how FLOAT is represented in binary

SIGN BIT|<-----EXPONENT---->|<-----Mantisa---->>>> to bit 64
S|E E E E E E E E E E|M M M M M M M M M
Power of 2 0|1 0 0 0 0 0 0 0 0 0|0 0 0 0 0 0 0 0 1 ... translates to 1/(2^(Power of 2))during calculation
1|0 9 8 7 6 5 4 3 2 1|2 3 4 5 6 7 8 9 0 ... ETC
| |
BitNum 0|0 0 0 0 0 0 0 0 1 1|1 1 1 1 1 1 1 1 2
1|2 3 4 5 6 7 8 9 0 1|2 3 4 5 6 7 8 9 0 ... etc



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

jp2code
Posting Yak Master

175 Posts

Posted - 2009-02-12 : 10:01:23
Using a Double fixed my problem. Thanks, Peso!

The goofy part about this database is that the field I'm reading is used as a boolean value, and no one knows why a float is being used there:

Admin = (float)((double)DataRow1[ADMIN]);



Avoid Sears Home Improvement
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-12 : 10:32:52
wow! Float for boolean...that looks like a cool design
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 10:39:40
Disks are cheap these days...



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-02-12 : 10:40:13
I'd pick the charitable word "interesting" myself to describe that.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -