Minor tweaks to Excel functions to handle envelope cases

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85866 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-01-30 00:41:52 +00:00
parent 695edbf677
commit 42fa6f10a1

View File

@ -1241,29 +1241,25 @@ class PHPExcel_Calculation_MathTrig {
* Truncates value to the number of fractional digits by number_digits. * Truncates value to the number of fractional digits by number_digits.
* *
* @param float $value * @param float $value
* @param int $number_digits * @param int $digits
* @return float Truncated value * @return float Truncated value
*/ */
public static function TRUNC($value = 0, $number_digits = 0) { public static function TRUNC($value = 0, $digits = 0) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$number_digits = PHPExcel_Calculation_Functions::flattenSingleValue($number_digits); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
// Validate parameters // Validate parameters
if ($number_digits < 0) { if ((!is_numeric($value)) || (!is_numeric($digits)))
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} $digits = floor($digits);
// Truncate // Truncate
if ($number_digits > 0) { $adjust = pow(10, $digits);
$value = $value * pow(10, $number_digits);
}
$value = intval($value);
if ($number_digits > 0) {
$value = $value / pow(10, $number_digits);
}
// Return if (($digits > 0) && (rtrim(intval((abs($value) - abs(intval($value))) * $adjust),'0') < $adjust/10))
return $value; return $value;
return (intval($value * $adjust)) / $adjust;
} // function TRUNC() } // function TRUNC()
} // class PHPExcel_Calculation_MathTrig } // class PHPExcel_Calculation_MathTrig