You are here

public static function PHPExcel_Calculation_MathTrig::TRUNC in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php \PHPExcel_Calculation_MathTrig::TRUNC()

* TRUNC * * Truncates value to the number of fractional digits by number_digits. * *

Parameters

float $value: * @param int $digits * @return float Truncated value

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php, line 1358

Class

PHPExcel_Calculation_MathTrig
PHPExcel_Calculation_MathTrig

Code

public static function TRUNC($value = 0, $digits = 0) {
  $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);

  // Validate parameters
  if (!is_numeric($value) || !is_numeric($digits)) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $digits = floor($digits);

  // Truncate
  $adjust = pow(10, $digits);
  if ($digits > 0 && rtrim(intval((abs($value) - abs(intval($value))) * $adjust), '0') < $adjust / 10) {
    return $value;
  }
  return intval($value * $adjust) / $adjust;
}