Oct: Difference between revisions
Jump to navigation
Jump to search
Add javascript snippet |
|||
Line 5: | Line 5: | ||
Oct returns a string representation of the octal (base 8) value of a number. The required parameter, ''number'', is any valid numeric expression. If ''number'' is not a whole number, it is rounded to the nearest whole number before being converted. | Oct returns a string representation of the octal (base 8) value of a number. The required parameter, ''number'', is any valid numeric expression. If ''number'' is not a whole number, it is rounded to the nearest whole number before being converted. | ||
== Example == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 13: | Line 13: | ||
Print "1 in octal:", Oct(1) | Print "1 in octal:", Oct(1) | ||
Print "2605.45 in octal:", Oct(2605.45) | Print "2605.45 in octal:", Oct(2605.45) | ||
</pre> | |||
== Example (JavaScript) == | |||
<pre> | |||
// Oct Example | |||
/* Oct returns a number as an octal string */ | |||
function Oct(n) { | |||
n=Math.round(n); | |||
if (n < 0) { | |||
n = 0177777 + n + 1; | |||
} | |||
return n.toString(8); | |||
} | |||
NSB.Print("68 in octal:" + " " + Oct(68) + "<br>"); | |||
NSB.Print("1 in octal:" + " " + Oct(1) + "<br>"); | |||
NSB.Print("2605.45 in octal:" + " " + Oct(2605.45) + "<br>"); | |||
</pre> | </pre> | ||
Revision as of 22:03, 19 May 2013
Oct(number)
Description
Oct returns a string representation of the octal (base 8) value of a number. The required parameter, number, is any valid numeric expression. If number is not a whole number, it is rounded to the nearest whole number before being converted.
Example (Basic)
Rem Oct Example 'Oct returns a number as an octal string Print "68 in octal:", Oct(68) Print "1 in octal:", Oct(1) Print "2605.45 in octal:", Oct(2605.45)
Example (JavaScript)
// Oct Example /* Oct returns a number as an octal string */ function Oct(n) { n=Math.round(n); if (n < 0) { n = 0177777 + n + 1; } return n.toString(8); } NSB.Print("68 in octal:" + " " + Oct(68) + "<br>"); NSB.Print("1 in octal:" + " " + Oct(1) + "<br>"); NSB.Print("2605.45 in octal:" + " " + Oct(2605.45) + "<br>");
Output
68 in octal: 104 1 in octal: 1 2605.45 in octal: 5055