[英]PMT function excel formula when the rate is zero
我試圖在SQL Server中使用MS Excel中的PMT函數來實現一個功能。
當我在Excel中使用時
=PMT(0;3;-29590)
給我這個結果:
$9,863.33
當我嘗試任何公式時,請給我除以零誤差。 我有3個時期的付款,沒有任何利率。 那么我該如何解決這個問題呢?
這是實際的功能:
create function dbo.PMT
(
@rate float,
@periods smallint,
@principal numeric(20,2)
)
returns numeric (38,9)
as
begin
declare @pmt numeric (38,9)
declare @WK_periods float,
@WK_principal float,
@wk_One float,
@WK_power float
select @WK_periods = @periods,
@WK_principal = @principal,
@WK_One = 1
select @pmt =
round(
( @WK_principal * (@rate*power(@WK_One+@rate,@WK_periods)))
/ (power(@WK_One+@rate,@WK_periods)-@WK_One)
,9)
return @pmt
end
在函數中添加一個簡單的if
if (@rate = 0)
select @pmt = (@principal / @periods) * -1
else
select @pmt =
round(
( @WK_principal * (@rate*power(@WK_One+@rate,@WK_periods)))
/ (power(@WK_One+@rate,@WK_periods)-@WK_One)
,9)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.