Solved

Ms SQL server 2005 datacasting

Posted on 2011-09-28
2
196 Views
Last Modified: 2012-08-13
What's the difference between a float, decimal, int casting?

If I have a value at '-2.5'
And I pull in from a table via nvarchar, how can I recast to do mathematical calculations on it.
0
Comment
Question by:GlobaLevel
2 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36717360
floating point arithmetic is most commonly used for accounting and financial data. Decimal is used when precision isn't quite as important. The integer type is for when you don't want to worry about decimal points at all.

In most cases, a decimal will suffice for "normal" calculations, so you can simply do:

DECLARE @myDecimal As Decimal(18,5)
SET @myDecimal = CAST(@myNVarchar, Decimal(18,5))
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36717565
>floating point arithmetic is most commonly used for accounting and financial data. Decimal is used when precision isn't quite as important.

That's backwards, my friend.


Int's are exact, but do not carry decimal points.

Like int's, decimal's are also exact.  But, they can be more precise to the number of decimal points given in the declaration.  Decimals are excellent for accounting and financial data where decimals are needed and accuracy is critical.

Float's are approximations, meaning, not all numbers can be represented exactly.  They can have high precision (lots of decimal places) using less space than decimals--thus you trade accuracy for space.  Float's are useful for very large or small numbers where exactness is not critical.  
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question