如何在Google表格上计算现值(PV)?

Google表格上的PV公式可能需要3,4或5个参数。 我正在尝试使用JavaScript中的参数来计算当前值,但似乎无法找出Google Sheets正在使用的公式。

传递给函数的参数当前是= PV(.00115,7.57,$ 66.88),函数的输出是$ 503.89。 这是如何计算的? 我需要在JavaScript中复制这个公式,或者找一些types的函数库来实现这个function。

经过咨询维基百科,我想出了这个function,它返回相同的结果内置PV 。 通过将其作为自定义函数进行testing,然后向其中抛出一些随机值进行testing。

 function myPV(rate, num, amount, remain, type) { if (type == 0) { var factor = (rate == 0 ? num : (1 - Math.pow(1+rate, -num))/rate); return -amount*factor - remain * Math.pow(1+rate, -num); } else { var factor = (rate == 0 ? num : (1 - Math.pow(1+rate, -num))*(1+rate)/rate); return -amount*factor - remain * Math.pow(1+rate, -num); } }