查詢

decoct()函式—用法及示例

「 將十進位制數轉換為八進位制數 」


函式名稱:decoct()

函式描述:decoct() 函式將十進位制數轉換為八進位制數。

相容版本:PHP 4, PHP 5, PHP 7

用法: decoct(int $number): string

引數:

  • $number: 必需,要轉換的十進位制數。

返回值:

  • 返回一個字串,表示 $number 的八進位制表示。

示例:

$number = 10;
$octal = decoct($number);
echo "十進位制數 {$number} 的八進位制表示為: {$octal}";  // 輸出:十進位制數 10 的八進位制表示為: 12

$number = 255;
$octal = decoct($number);
echo "十進位制數 {$number} 的八進位制表示為: {$octal}";  // 輸出:十進位制數 255 的八進位制表示為: 377

$number = 512;
$octal = decoct($number);
echo "十進位制數 {$number} 的八進位制表示為: {$octal}";  // 輸出:十進位制數 512 的八進位制表示為: 1000

注意事項:

  • 如果輸入的十進位制數超過 PHP 的整數範圍,則返回的八進位制表示可能不準確。
  • 如果不是一個整數,decoct() 函式會在轉換之前將其截斷為整型。
補充糾錯
上一個函式: decbin()函式
下一個函式: define()函式
熱門PHP函式
分享連結