Solved

Ms SQL server 2005 datacasting

Posted on 2011-09-28
2
188 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
Comment Utility
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
Comment Utility
>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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now