当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Calculation_DateTime::DATEDIF方法代码示例

本文整理汇总了PHP中PHPExcel_Calculation_DateTime::DATEDIF方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Calculation_DateTime::DATEDIF方法的具体用法?PHP PHPExcel_Calculation_DateTime::DATEDIF怎么用?PHP PHPExcel_Calculation_DateTime::DATEDIF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPExcel_Calculation_DateTime的用法示例。


在下文中一共展示了PHPExcel_Calculation_DateTime::DATEDIF方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: XNPV

 /**
  * XNPV
  *
  * Returns the net present value for a schedule of cash flows that is not necessarily periodic.
  * To calculate the net present value for a series of cash flows that is periodic, use the NPV function.
  *
  * Excel Function:
  *		=XNPV(rate,values,dates)
  *
  * @param	float			$rate		The discount rate to apply to the cash flows.
  * @param	array of float	$values		A series of cash flows that corresponds to a schedule of payments in dates. The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. The series of values must contain at least one positive value and one negative value.
  * @param	array of mixed	$dates		A schedule of payment dates that corresponds to the cash flow payments. The first payment date indicates the beginning of the schedule of payments. All other dates must be later than this date, but they may occur in any order.
  * @return	float
  */
 public static function XNPV($rate, $values, $dates)
 {
     $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
     if (!is_numeric($rate)) {
         return PHPExcel_Calculation_Functions::VALUE();
     }
     if (!is_array($values) || !is_array($dates)) {
         return PHPExcel_Calculation_Functions::VALUE();
     }
     $values = PHPExcel_Calculation_Functions::flattenArray($values);
     $dates = PHPExcel_Calculation_Functions::flattenArray($dates);
     $valCount = count($values);
     if ($valCount != count($dates)) {
         return PHPExcel_Calculation_Functions::NaN();
     }
     if (min($values) > 0 || max($values) < 0) {
         return PHPExcel_Calculation_Functions::VALUE();
     }
     $xnpv = 0.0;
     for ($i = 0; $i < $valCount; ++$i) {
         if (!is_numeric($values[$i])) {
             return PHPExcel_Calculation_Functions::VALUE();
         }
         $xnpv += $values[$i] / pow(1 + $rate, PHPExcel_Calculation_DateTime::DATEDIF($dates[0], $dates[$i], 'd') / 365);
     }
     return is_finite($xnpv) ? $xnpv : PHPExcel_Calculation_Functions::VALUE();
 }
开发者ID:arjunkumar786,项目名称:faces,代码行数:41,代码来源:Financial.php


注:本文中的PHPExcel_Calculation_DateTime::DATEDIF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。