calculation

  • I am trying to do this calculation in a stored procedure but I just get zeros until I get to 12 if @NumPayments = 12.

    (num.number + 1)/@NumPayments

    I am sure this is because it is rounding the result and is not showing the decimal value. How do I change it so it places the decimal value in the table?

  • (num.number + 1.0)/@NumPayments

    Or declare @NumPayments as decimal if it's possible... but I'd got with + 1.0

  • You might want to post a little of your code.  If you really have some type of 'IF' clause like that shown below it won't divide until you @NumPayments = 12; not 11 or 10 or any other number.

    if @NumPayments = 12

        (num.number + 1)/@NumPayments

  • anything between 0 and 11 (int) divided by 12 (int) = 0, then 1 untill you get to 24. That's why I changed the 1 to 1.0 (decimal) / (int) = (decimal)

  • I believe you missed the point I was trying to make.  Your (num.number + 1)/@NumPayments) statement only fires when @NumPayment = 12.  That's why I suggested posting the code; so we could look at the unambiguous code rather than a statement of content.  Since I only inferred from your first statement that the code contained an IF statement, my earlier post could be based on a faulty assumption.

     

     

  • we're both making assumptions and without the code there's no point in continuing this discussion.. I'll wait for his answer before drawing any final conclusion.

  • changing the 1 to 1.0 did the trick - thank you

  • NP.

  • NP

    What does this stand for?

     

    Curtis,

    I believe this only to be a small part of your proc. What are you dealing with? By any chance, are you dealing a time value of money problem? I might be wrong, but to me this looks like you're doing some compounding here. If so, here's what I use for monthly compounding (@NumPayments = 12 in your case)

    DECLARE @pv FLOAT

    DECLARE @i FLOAT

    DECLARE @m FLOAT

    DECLARE @n FLOAT

    SELECT

     @pv=1000000, @i=0.06, @m=12, @n=1

    SELECT

     @pv*POWER(1+@i/@m,@m*@n)

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • NP = No problems

    HTH = Happy to help

  • Thanks!

    I should have flipped to page 3 here http://www.acronymfinder.com/af-query.asp?acronym=np&String=exact&page=3 

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Frank

    I am doing compounding. My procedure is similar to the way you do it.

    Thanks for the input!

  • --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply