Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Difference between Numeric and Float


Difference between Numeric and Float

Author
Message
Ezhilan
Ezhilan
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
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
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14383 Visits: 9729
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search