Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Difference between Numeric and Float Expand / Collapse
Author
Message
Posted Friday, June 27, 2008 4:29 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 8, 2009 10:24 AM
Points: 63, Visits: 61
Hi all,

I am getting error message while trying to insert Float datatype values into Numeric datatype column. How can we avoid this ?

Also, please tell me what is the difference between float and numeric datatypes.

Thanks,
Ezhilan
Post #524869
Posted Friday, June 27, 2008 12:37 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
Numeric (also called Decimal) has a defined precision and scale. Float just uses defaults for that.

You can end up with overflow errors because of this.

For example, if you define a column/variable as Numeric(10,8), you are defining it with a total of 10 digits, and 8 of them are the right of the decimal place. If you try to insert any number >= 100 into this, it will give an error. A Float data type can handle those numbers quite easily, so that conversion will give you errors. (It can go the other way as well, if you have a float with 10 digits to the right of the decimal, and put them in a numeric with only 8, it will cut off the last two digits. Won't give an error, but will drop the precision.)

That's probably what's happening to you. Many people define numeric (decimal) data types for the largest precision they think will happen, and don't realize they are reducing the number of allowed digits to the left of the decimal.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #525280
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse