DEC2OCT function
PRO
BASIC
The DEC2OCT
function in Jspreadsheet Formulas Pro is a tool used for converting decimal numbers into octal format. This is particularly helpful when dealing with mathematical problems or data that requires the octal numeral system. To use it, simply input your decimal number into the function and it will output the equivalent in octal format. It's a simple and effective way of transforming your data between these two numerical systems.
Documentation
Converts a decimal number to octal format.
Category
Engineering
Syntax
DEC2OCT(number, [places])
Parameter | Description |
---|---|
number |
The decimal number you want to convert to octal. |
[places] |
Optional. The minimum number of characters to use for the octal number. If omitted or zero, the function will use as many characters as necessary. |
Behavior
The DEC2OCT
function is used to convert decimal numbers to octal. This function takes two arguments: the decimal number you want to convert, and an optional argument that specifies the number of characters to use.
- If the function is given an empty cell, it will return a
#NUM!
error. - If the function is provided with text instead of a number, it will return a
#VALUE!
error. - Booleans are treated as numbers:
TRUE
is treated as 1 andFALSE
as 0. - When the number provided is negative, the function will return a two's complement octal value.
- If the number provided is not an integer, the function will truncate it before converting.
- If the number of characters specified is less than the minimum number of characters needed to represent the number, the function will ignore this argument and use as many characters as needed.
Common Errors
Error | Description |
---|---|
#NUM! |
Occurs if the number is outside the range -549,755,813,888 to 549,755,813,887, or if places is negative. |
#VALUE! |
Occurs if an argument that is not a number is used. |
Best practices
- Always ensure that the number you are converting is within the allowable range to avoid
#NUM!
error.- Be aware that the function will truncate non-integer numbers before converting. If you want to convert a decimal number with fractional part, you should handle the fractional part separately.
- When specifying the number of characters to use, ensure it is not less than the minimum needed to represent the number in octal.
- Keep in mind that the function treats booleans as numbers. If you do not intend this behavior, you should convert booleans to text before passing them to the function.
Usage
A few examples using the DEC2OCT function.
DEC2OCT(255) ➝ 377
// Converts 255 to octal (base 8)
DEC2OCT(42, 4) ➝ 0052
// Converts 42 and pads result to 4 characters with leading zeros
DEC2OCT(1000) ➝ 1750
// Converts 1000 to its octal equivalent
DEC2OCT(-1) ➝ 7777777777
// Negative number returns 10-digit octal using two’s complement
DEC2OCT(12.9) ➝ 14
// Decimal truncated before conversion
DEC2OCT("Hello") ➝ #VALUE!
// Non-numeric input returns error
Interactive Spreadsheet Demo
<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>
<div id="spreadsheet"></div>
<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('OGFjMTAyMjQyODk1ZTNmYzY4ZThmMjMzMjNjOTBhYTNiMGFkZTlmZjFmODliMzAxODNjMmRmN2M5N2YwYTI1ZTk4NmIwNjE2MmRmNzI4ZjI5YzY4OGViM2FhMzMxOGMyOWQ0MTJlZTZmNjNkM2E0ZTJjNjcxOTRhZWM0ZWVlNWEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF5TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
data: [
[
"Decimal",
"Octal",
"Octal (4 places)"
],
[
255,
"=DEC2OCT(A2)",
"=DEC2OCT(A2,4)"
],
[
42,
"=DEC2OCT(A3)",
"=DEC2OCT(A3,4)"
],
[
100,
"=DEC2OCT(A4)",
"=DEC2OCT(A4,4)"
],
[
512,
"=DEC2OCT(A5)",
"=DEC2OCT(A5,4)"
]
]
}]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
// Set license
jspreadsheet.setLicense('OGFjMTAyMjQyODk1ZTNmYzY4ZThmMjMzMjNjOTBhYTNiMGFkZTlmZjFmODliMzAxODNjMmRmN2M5N2YwYTI1ZTk4NmIwNjE2MmRmNzI4ZjI5YzY4OGViM2FhMzMxOGMyOWQ0MTJlZTZmNjNkM2E0ZTJjNjcxOTRhZWM0ZWVlNWEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF5TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Worksheet data
const data = [
[
"Decimal",
"Octal",
"Octal (4 places)"
],
[
255,
"=DEC2OCT(A2)",
"=DEC2OCT(A2,4)"
],
[
42,
"=DEC2OCT(A3)",
"=DEC2OCT(A3,4)"
],
[
100,
"=DEC2OCT(A4)",
"=DEC2OCT(A4,4)"
],
[
512,
"=DEC2OCT(A5)",
"=DEC2OCT(A5,4)"
]
];
// Render component
return (
<Spreadsheet ref={spreadsheet}>
<Worksheet data={data} />
</Spreadsheet>
);
}
<template>
<Spreadsheet ref="spreadsheet">
<Worksheet :data="data" />
</Spreadsheet>
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";
// Set license
jspreadsheet.setLicense('OGFjMTAyMjQyODk1ZTNmYzY4ZThmMjMzMjNjOTBhYTNiMGFkZTlmZjFmODliMzAxODNjMmRmN2M5N2YwYTI1ZTk4NmIwNjE2MmRmNzI4ZjI5YzY4OGViM2FhMzMxOGMyOWQ0MTJlZTZmNjNkM2E0ZTJjNjcxOTRhZWM0ZWVlNWEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF5TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default {
components: {
Spreadsheet,
Worksheet,
},
data() {
// Worksheet data
const data = [
[
"Decimal",
"Octal",
"Octal (4 places)"
],
[
255,
"=DEC2OCT(A2)",
"=DEC2OCT(A2,4)"
],
[
42,
"=DEC2OCT(A3)",
"=DEC2OCT(A3,4)"
],
[
100,
"=DEC2OCT(A4)",
"=DEC2OCT(A4,4)"
],
[
512,
"=DEC2OCT(A5)",
"=DEC2OCT(A5,4)"
]
]
return {
data
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import * as formula from "@jspreadsheet/formula-pro";
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('OGFjMTAyMjQyODk1ZTNmYzY4ZThmMjMzMjNjOTBhYTNiMGFkZTlmZjFmODliMzAxODNjMmRmN2M5N2YwYTI1ZTk4NmIwNjE2MmRmNzI4ZjI5YzY4OGViM2FhMzMxOGMyOWQ0MTJlZTZmNjNkM2E0ZTJjNjcxOTRhZWM0ZWVlNWEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF5TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
@Component({
standalone: true,
selector: "app-root",
template: `<div #spreadsheet></div>`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [{
data: [
[
"Decimal",
"Octal",
"Octal (4 places)"
],
[
255,
"=DEC2OCT(A2)",
"=DEC2OCT(A2,4)"
],
[
42,
"=DEC2OCT(A3)",
"=DEC2OCT(A3,4)"
],
[
100,
"=DEC2OCT(A4)",
"=DEC2OCT(A4,4)"
],
[
512,
"=DEC2OCT(A5)",
"=DEC2OCT(A5,4)"
]
]
}]
});
}
}