Hello All
I am trying to perform the following calculation
100^(-.01*25)
Here is the code I have right now
declare @decay_rate decimal;
declare @decay_days decimal;
declare @decay_calc decimal;
declare @power decimal;
set @decay_rate = 0.01
if(datediff(d,@endperiod,getdate()) > 5)
begin
set @decay_days = datediff(d,@endperiod,getdate())
set @power=(@decay_days*@decay_rate)
set @decay_calc = (power(100,(@power)))
--=(100^((B6*B7)))*100
What am I doing wrong here?
I keep getting the value as 0 can someone help please
Thanks
Shri
Mariano Gomez - 01 Dec 2008 21:41 GMT
The value 100 is casting the expression to integer, replace as follows:
set @decay_calc = power(100.00000, @power)
I am not sure what level of precision you are looking for, but you can
reduce/increase the decimals after 100 as you see fit, or simply store the
value 100 in a decimal variable as well.
Best regards,
--
MG.-
Mariano Gomez, MIS, MCP, PMP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com
The Dynamics GP Blogster at http://dynamicsgpblogster.blogspot.com
> Hello All
> I am trying to perform the following calculation
[quoted text clipped - 22 lines]
> Thanks
> Shri
Plamen Ratchev - 01 Dec 2008 21:48 GMT
You declared all of your variables as DECIMAL without specifying
precision and scale. When you do not define them the default precision
is 18 and the default scale is 0. That converts the value 0.01 to 0.
Try this:
DECLARE @decay_rate DECIMAL;
SET @decay_rate = 0.01;
SELECT @decay_rate;
/* returns 0 */
GO
DECLARE @decay_rate DECIMAL(18, 2);
SET @decay_rate = 0.01;
SELECT @decay_rate;
/* returns 0.01 */
Declare all variables with correct precision and scale and your
calculation should work.

Signature
Plamen Ratchev
http://www.SQLStudio.com
Mariano Gomez - 01 Dec 2008 22:15 GMT
That's correct! I did not notice this to begin with!
Best regards,
--
MG.-
Mariano Gomez, MIS, MCP, PMP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com
The Dynamics GP Blogster at http://dynamicsgpblogster.blogspot.com
> You declared all of your variables as DECIMAL without specifying
> precision and scale. When you do not define them the default precision
[quoted text clipped - 18 lines]
> Declare all variables with correct precision and scale and your
> calculation should work.