answersLogoWhite

0

JavaScript doesn't come prepared to do much in the way of base changing operations. But the easiest way to get a number to change it's base from decimal to octal is using the Number.toString() method.

Simply assign your decimal value to a variable:

var ourNumber = 10;

Then call the toString() method, passing in the base you want for output as a parameter.

var ourNumberInOctal = ourNumber.toString(8); //yeilds "12"

I've gone ahead and created a complete example at JSFiddle for you. Please see the related link.

User Avatar

Wiki User

13y ago

What else can I help you with?