Exemplo n.º 1
0
 /**
  * DOLLAR
  *
  * This function converts a number to text using currency format, with the decimals rounded to the specified place.
  * The format used is $#,##0.00_);($#,##0.00)..
  *
  * @param    float    $value            The value to format
  * @param    int        $decimals        The number of digits to display to the right of the decimal point.
  *                                    If decimals is negative, number is rounded to the left of the decimal point.
  *                                    If you omit decimals, it is assumed to be 2
  * @return    string
  */
 public static function DOLLAR($value = 0, $decimals = 2)
 {
     $value = Functions::flattenSingleValue($value);
     $decimals = is_null($decimals) ? 0 : Functions::flattenSingleValue($decimals);
     // Validate parameters
     if (!is_numeric($value) || !is_numeric($decimals)) {
         return Functions::NAN();
     }
     $decimals = floor($decimals);
     $mask = '$#,##0';
     if ($decimals > 0) {
         $mask .= '.' . str_repeat('0', $decimals);
     } else {
         $round = pow(10, abs($decimals));
         if ($value < 0) {
             $round = 0 - $round;
         }
         $value = MathTrig::MROUND($value, $round);
     }
     return \PHPExcel\Style\NumberFormat::toFormattedString($value, $mask);
 }
Exemplo n.º 2
0
 /**
  * DSUM
  *
  * Adds the numbers in a column of a list or database that match conditions that you specify.
  *
  * Excel Function:
  *        DSUM(database,field,criteria)
  *
  * @access    public
  * @category Database Functions
  * @param    mixed[]            $database    The range of cells that makes up the list or database.
  *                                        A database is a list of related data in which rows of related
  *                                        information are records, and columns of data are fields. The
  *                                        first row of the list contains labels for each column.
  * @param    string|integer    $field        Indicates which column is used in the function. Enter the
  *                                        column label enclosed between double quotation marks, such as
  *                                        "Age" or "Yield," or a number (without quotation marks) that
  *                                        represents the position of the column within the list: 1 for
  *                                        the first column, 2 for the second column, and so on.
  * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
  *                                        You can use any range for the criteria argument, as long as it
  *                                        includes at least one column label and at least one cell below
  *                                        the column label in which you specify a condition for the
  *                                        column.
  * @return    float
  *
  */
 public static function DSUM($database, $field, $criteria)
 {
     $field = self::fieldExtract($database, $field);
     if (is_null($field)) {
         return null;
     }
     // Return
     return MathTrig::SUM(self::getFilteredColumn($database, $field, $criteria));
 }
Exemplo n.º 3
0
 /**
  * POISSON
  *
  * Returns the Poisson distribution. A common application of the Poisson distribution
  * is predicting the number of events over a specific time, such as the number of
  * cars arriving at a toll plaza in 1 minute.
  *
  * @param    float        $value
  * @param    float        $mean        Mean Value
  * @param    boolean        $cumulative
  * @return    float
  *
  */
 public static function POISSON($value, $mean, $cumulative)
 {
     $value = Functions::flattenSingleValue($value);
     $mean = Functions::flattenSingleValue($mean);
     if (is_numeric($value) && is_numeric($mean)) {
         if ($value < 0 || $mean <= 0) {
             return Functions::NAN();
         }
         if (is_numeric($cumulative) || is_bool($cumulative)) {
             if ($cumulative) {
                 $summer = 0;
                 for ($i = 0; $i <= floor($value); ++$i) {
                     $summer += pow($mean, $i) / MathTrig::FACT($i);
                 }
                 return exp(0 - $mean) * $summer;
             } else {
                 return exp(0 - $mean) * pow($mean, $value) / MathTrig::FACT($value);
             }
         }
     }
     return Functions::VALUE();
 }
Exemplo n.º 4
0
 /**
  *    BESSELJ
  *
  *    Returns the Bessel function
  *
  *    Excel Function:
  *        BESSELJ(x,ord)
  *
  * @access    public
  * @category Engineering Functions
  * @param    float $x The value at which to evaluate the function.
  *                                If x is nonnumeric, BESSELJ returns the #VALUE! error value.
  * @param    integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  *                                If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
  *                                If $ord < 0, BESSELJ returns the #NUM! error value.
  * @return    float
  *
  */
 public static function BESSELJ($x, $ord)
 {
     $x = is_null($x) ? 0.0 : Functions::flattenSingleValue($x);
     $ord = is_null($ord) ? 0.0 : Functions::flattenSingleValue($ord);
     if (is_numeric($x) && is_numeric($ord)) {
         $ord = floor($ord);
         if ($ord < 0) {
             return Functions::NAN();
         }
         $fResult = 0;
         if (abs($x) <= 30) {
             $fResult = $fTerm = pow($x / 2, $ord) / MathTrig::FACT($ord);
             $ordK = 1;
             $fSqrX = $x * $x / -4;
             do {
                 $fTerm *= $fSqrX;
                 $fTerm /= $ordK * ($ordK + $ord);
                 $fResult += $fTerm;
             } while (abs($fTerm) > 1.0E-12 && ++$ordK < 100);
         } else {
             $f_PI_DIV_2 = M_PI / 2;
             $f_PI_DIV_4 = M_PI / 4;
             $fXAbs = abs($x);
             $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
             if ($ord & 1 && $x < 0) {
                 $fResult = -$fResult;
             }
         }
         return is_nan($fResult) ? Functions::NAN() : $fResult;
     }
     return Functions::VALUE();
 }