【问题标题】:PMT function excel formula when the rate is zero率为零时的PMT函数excel公式
【发布时间】:2018-08-23 20:52:44
【问题描述】:

我尝试在 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

【问题讨论】:

  • 无论如何,付款只是principal/periods*-1,所以在检查@rate 是否为0 时输入IF,然后进行简单的除法。

标签: sql-server excel financial


【解决方案1】:

在你的函数中添加一个简单的 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-14
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    相关资源
    最近更新 更多