Never mind! My bad. I had the wrong balance. Not SQL's fault.
TSQL returning the wrong calculation results
I'm very confused. I've been working on this for hours. I have a query:
set @interest = @balance * power(1.0 + @curIrate / 365.0,@days) - @balance
select @checkDate checkDate, @interest interest, @balance balance, @curIrate curIrate, @days days
The 'select' returns:
checkDate interest balance curIrate days
2011-12-01 00:00:00.0 16.0088 11447.50000 0.0170030 30
which calculates a clearly wrong interest amount. Yet if I run this as a stand-alone query I get:
select 1147.50 * power(1.0 + 0.0170030 / 365.0, 30) - 1147.50
1.6047228
which is correct. Why is the TSQL query calculating 16.0088 and not 1.6047228?
Declares:
@interest money
@balance decimal(14,5)
@iRate decimal(10,7)
@days integer