{"record":{"id":"adc7b6bce74e4cca","repo":"PHPOffice/PhpSpreadsheet","slug":"value-adc7b6","errorCode":"#VALUE!","errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"error_code","errorClass":"PhpOffice\\PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php","lineNumber":208,"sourceCode":"            $places = self::validatePlaces($places);\n        } catch (Exception $e) {\n            return $e->getMessage();\n        }\n\n        $value = (int) floor((float) $value);\n        if ($value > self::LARGEST_OCTAL_IN_DECIMAL || $value < self::SMALLEST_OCTAL_IN_DECIMAL) {\n            return ExcelError::NAN();\n        }\n        $r = decoct($value);\n        $r = substr($r, -10);\n\n        return self::nbrConversionFormat($r, $places);\n    }\n\n    protected static function validateDecimal(string $value): string\n    {\n        if (strlen($value) > preg_match_all('/[-0123456789.]/', $value)) {\n            throw new Exception(ExcelError::VALUE());\n        }\n\n        return $value;\n    }\n}\n","sourceCodeStart":190,"sourceCodeEnd":214,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php#L190-L214","documentation":"#VALUE! from the decimal validator used by DEC2BIN, DEC2HEX and DEC2OCT. ConvertDecimal::validateDecimal() only permits characters in [-0123456789.] - anything else (comma, space, 'e', currency symbols) makes strlen exceed the preg_match_all count and throws Calculation\\Exception('#VALUE!'), returned as the result string.","triggerScenarios":"=DEC2BIN(\"1,000\") (thousands separator), =DEC2HEX(\"1e5\") ('e' is rejected), =DEC2BIN(\" 42\") (leading space), =DEC2BIN(\"12a\"); PHP calls ConvertDecimal::toBinary(number_format(1000)) where number_format produced '1,000'.","commonSituations":"Numbers formatted with number_format() or locale thousands separators before conversion; scientific-notation strings from JSON/float serialization; values pasted from text with stray characters.","solutions":["Pass plain numeric strings or ints: strip thousands separators (str_replace(',', '', $v)) and trim whitespace.","Cast genuinely numeric values with (int) or (float) before calling - is_numeric values survive validateValue, but the cleanest fix is a real int.","For scientific notation, cast through (int) (float) $value first.","Check results for '#VALUE!' when decimal strings come from imports."],"exampleFix":"// before\n$bin = ConvertDecimal::toBinary(number_format(1000)); // '1,000' -> '#VALUE!'\n\n// after\n$bin = ConvertDecimal::toBinary((int) str_replace([',', ' '], '', '1,000'));","handlingStrategy":"validation","validationCode":"$dec = (is_numeric($value)) ? (string) (int) $value : preg_replace('/[^0-9.+-]/', '', $value);\nif (!preg_match('/^[-+]?\\d+(\\.\\d+)?$/', $dec)) {\n    throw new \\InvalidArgumentException('decimal value contains invalid characters');\n}\n$result = ConvertDecimal::toBinary($dec);","typeGuard":"/** DEC2* input: only digits, minus and dot are legal. */\nfunction isValidDecimalString(mixed $v): bool\n{\n    return is_string($v) && preg_match('/^[-+]?\\d+(\\.\\d+)?$/', $v) === 1;\n}","tryCatchPattern":null,"preventionTips":["Never feed number_format() output to DEC2* functions - it contains thousands separators.","Cast scientific-notation strings through (int)/(float) before conversion.","Trim whitespace from pasted/imported values."],"tags":["phpspreadsheet","excel-formula","base-conversion","decimal","locale-formatting"],"backgroundTag":"excel-value-error","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}