Use octal numbers in calculation in JavaScript

Description

The following code shows how to use octal numbers in calculation.

Example


<!--  w  w  w .  j a  v a 2s  .  co m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var octalNum = 056;
document.writeln(octalNum); //46
document.writeln("<br/>");

var aNum = 123;
document.writeln(octalNum + aNum); //169
</script>

</head>
<body>

</body>
</html>

Click to view the demo

The code above generates the following result.

Use octal numbers in calculation in JavaScript
Home »
  Javascript Tutorial »
    Data Type »
      Number
Javascript Tutorial Number
Add function to Number.prototype in JavaScr...
Add the float point numbers together in Jav...
Calculate Exponential for a number with toE...
Check if a string is a Not-A-Number with is...
Check if a string is representing a number ...
Check that Octal Integer literal can only h...
Compare NaN to a string in JavaScript
Compare NaN with other value in JavaScript
Compare a number to Number.NEGATIVE_INFINIT...
Compare a number to Number.NaN in JavaScrip...
Compare number to Number.POSITIVE_INFINITY ...
Compare number value to Number.MAX_VALUE in...
Compare number value to Number.MIN_VALUE in...
Compare two numbers for equal in JavaScript
Compare with positive Infinity in JavaScrip...
Crate a Not a Number in JavaScript
Create Floating-Point Numbers in scientific...
Create Hexadecimal integer in JavaScript
Create Number Object from literal in JavaSc...
Create Octal Integer literal by setting the...
Create a float Literal with no decimal part...
Create a float point type value in JavaScri...
Create a new number object from number lite...
Create a number type varible with number li...
Create a number with Scientific notation li...
Create a scientific notation saying take 1....
Create float type number with literal in Ja...
Create integer from a hexadecimal literal i...
Define and use integers in JavaScript
Divide two integers in JavaScript
Format numbers to a chosen number of decima...
Generate a random number in JavaScript
Get number value for the negative infinity ...
Get number value for the positive infinity ...
Get the max value for a number in JavaScrip...
Get the min value for a number in JavaScrip...
Get the primitive value of a Number object ...
Round decimal value up in JavaScript
Round number to a number with a specified n...
String with only number and minus sign, for...
Tell if the value is "not a number" with is...
Use Binary Flags with binary operators in J...
Use hexadecimal numbers in calculation in J...
Use if statement to check if a variable is ...
Use isFinite function to check if a number ...
Use isNaN to test boolean literal in JavaSc...
Use isNan to check if a value is a number i...
Use octal numbers in calculation in JavaScr...