Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

why does CAST round

 
   Database Help (Home) -> Programming RSS
Next:  Find duplicate record query  
Author Message
stevehunter_1

External


Since: Mar 02, 2008
Posts: 7



(Msg. 1) Posted: Mon Oct 30, 2006 12:44 pm
Post subject: why does CAST round
Archived from groups: microsoft>public>sqlserver>programming (more info?)

declare @test decimal(18,9)
SET @test = CAST('12.75' AS decimal)
PRINT @test

result = 13.00

Why not 12.75, what am i doing wrong??

 >> Stay informed about: why does CAST round 
Back to top
Login to vote
Razvan Socol

External


Since: Feb 03, 2008
Posts: 219



(Msg. 2) Posted: Mon Oct 30, 2006 12:47 pm
Post subject: Re: why does CAST round [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

You should specify the scale and precision for the decimal in the CAST
function, like this:

declare @test decimal(18,9)
SET @test = CAST('12.75' AS decimal(18,9))
PRINT @test

If you don't, SQL Server assumes that you want a decimal(18,0).

Razvan

wrote:
> declare @test decimal(18,9)
> SET @test = CAST('12.75' AS decimal)
> PRINT @test
>
> result = 13.00
>
> Why not 12.75, what am i doing wrong??

 >> Stay informed about: why does CAST round 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
MS SQL ROUND() vs. VB ROUND() - -- Luis Garcia IT Consultant

Cast & Convert - hi, how to cast or convert an nvarchar into a datetime ...' as in: (see WHEN 'datecreated' then Cast(d_date_created as datetime)) ----------------------------------- ALTER PROCEDURE [dbo].[SelectContactListTEST] @activeSearch bit,..

CAST and CONVERT - I ALWAYS seem to struggle with CAST and CONVERT...Maybe just because I don't use it that often. I have to perform some division. SQL follows... CUSTDATA.value/GEN.p_and_i AS 'Reserves Months' The CUSTDATA.value is a user-defined field built into....

CAST question - I have a column that has batch numbers, but it's a varchar column "WHERE batch between 1500 and 1625" I need to find out if that batch numbers are between 1500 and 1625, however I'm getting an error: The conversion of the varchar value '23933...

CAST or CONVERT during UPDATE - Hi I'm brand new to SQL and have finally (with much support) managed to get values from an Excel workbook updating a live SQL database using the following: sSQL = "UPDATE Clients SET [Org Commission]=' " & Range("F38") &a...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]