public static function PHPExcel_Calculation_Engineering::BINTOOCT in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Engineering.php \PHPExcel_Calculation_Engineering::BINTOOCT()
* BINTOOCT * * Return a binary value as octal. * * Excel Function: * BIN2OCT(x[,places]) * * @access public * @category Engineering Functions *
Parameters
string $x The binary number (as a string) that you want to convert. The number: * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2OCT returns the #NUM! error value. * @param integer $places The number of characters to use. If places is omitted, BIN2OCT uses the * minimum number of characters necessary. Places is useful for padding the * return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value. * If places is negative, BIN2OCT returns the #NUM! error value. * @return string
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Engineering.php, line 1170
Class
- PHPExcel_Calculation_Engineering
- PHPExcel_Calculation_Engineering
Code
public static function BINTOOCT($x, $places = NULL) {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
$places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
if (is_bool($x)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
$x = (int) $x;
}
else {
return PHPExcel_Calculation_Functions::VALUE();
}
}
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
$x = floor($x);
}
$x = (string) $x;
if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
return PHPExcel_Calculation_Functions::NaN();
}
if (strlen($x) > 10) {
return PHPExcel_Calculation_Functions::NaN();
}
elseif (strlen($x) == 10) {
// Two's Complement
return str_repeat('7', 7) . substr(strtoupper(decoct(bindec(substr($x, -9)))), -3);
}
$octVal = (string) decoct(bindec($x));
return self::_nbrConversionFormat($octVal, $places);
}