Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #557

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

Date 2011-07-21 09:23 +0200
From Henk van den Berg <me@myplace.net>
Newsgroups comp.databases.ms-sqlserver
Subject Re: Proper way to get decimal results from arithmetic with integers and decimals
References <ea0bbf58-8d97-40f0-aa30-efbb667237f4@f20g2000yqm.googlegroups.com>
Message-ID <4e27d412$0$23911$e4fe514c@news.xs4all.nl> (permalink)

Show all headers | View raw


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:
> 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.

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Proper way to get decimal results from arithmetic with integers and decimals BobRoyAce <broy@omegasoftwareinc.com> - 2011-07-20 21:36 -0700
  Re: Proper way to get decimal results from arithmetic with integers and decimals Henk van den Berg <me@myplace.net> - 2011-07-21 09:23 +0200
    Re: Proper way to get decimal results from arithmetic with integers and decimals BobRoyAce <broy@omegasoftwareinc.com> - 2011-07-22 00:08 -0700

csiph-web