dbTalk Databases Forums  

Proper way to get decimal results from arithmetic with integers and decimals

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Proper way to get decimal results from arithmetic with integers and decimals in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
BobRoyAce
 
Posts: n/a

Default Proper way to get decimal results from arithmetic with integers and decimals - 07-20-2011 , 11:36 PM






Let's say that I have a table with two fields: InfPctField and
DecimalField, where the first is of type INT and the latter is
DECIMAL(16,2).

When I write a query as...

SELECT DecimalField * IntPctField / 100. AS TheAnswer

TheAnswer comes back as ZERO followed by decimals, with all decimal
digits ZEROs (e.g. 0.00000).

What is the correct syntax to get back nonzero values?

For example, when DecimalField is 1200.00 and IntPctField is 30, I
should get 360.00.

Reply With Quote
  #2  
Old   
Henk van den Berg
 
Posts: n/a

Default Re: Proper way to get decimal results from arithmetic with integersand decimals - 07-21-2011 , 02:23 AM






Here's what I get:


declare @decimalField decimal(12,5)
declare @intpctfield int
set @decimalfield=1200.00
set @intpctfield=30
SELECT @DecimalField * @IntPctField / 100. AS TheAnswer


TheAnswer
-------------
360.000000000


So can you post your query that yields the results you mention? This may
shed some light on it.

Best,
Henk


BobRoyAce schreef op 21-07-2011 06:36:
Quote:
Let's say that I have a table with two fields: InfPctField and
DecimalField, where the first is of type INT and the latter is
DECIMAL(16,2).

When I write a query as...

SELECT DecimalField * IntPctField / 100. AS TheAnswer

TheAnswer comes back as ZERO followed by decimals, with all decimal
digits ZEROs (e.g. 0.00000).

What is the correct syntax to get back nonzero values?

For example, when DecimalField is 1200.00 and IntPctField is 30, I
should get 360.00.

Reply With Quote
  #3  
Old   
BobRoyAce
 
Posts: n/a

Default Re: Proper way to get decimal results from arithmetic with integersand decimals - 07-22-2011 , 02:08 AM



I think that I may have goofed...had bunch of records where the
decimal field equaled zero, and didn't look far enough in data to see
nonzero ones. Sorry, and thanks for help.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.