Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert decimal to Octal in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 06:13:02 09月28日 Update

This article introduces the relevant knowledge of "how to convert JavaScript from decimal to octal". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In JavaScript, you can use the toString () method to convert decimal to octal, which is used for string representation of numbers. When the parameter is set to "8", the number can be displayed in octal with the syntax "number.toString (8)".

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

How to convert decimal to Octal in JavaScript

JavaScript toString () method

A string representation used for numbers.

For example, when radix is 2, NumberObject is converted to a string represented by a binary value.

Grammar

Number.toString (radix)

Radix is optional. Specifies that the cardinality that represents a number is an integer between 2 and 36. If this parameter is omitted, the cardinality of 10 is used. Note, however, that if the parameter is a value other than 10, the ECMAScript standard allows the implementation to return any value.

2-numbers are displayed as binary valu

8-numbers are displayed as octal valu

16-numbers are displayed as hexadecimal valu

Examples are as follows:

Rookie tutorial (runoob.com) Click the button to display the formatted number

Tags: Binary numbers parameters characters strings methods binary content cardinality tutorials more knowledge grammar output practical learned and then in between octal hexadecimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux Apple Microsoft Xiaomi