Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert a string to octal in javascript

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Most people do not understand the knowledge points of this article "how to convert strings to octal in javascript", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to convert strings to octal in javascript" article.

Javascript string to octal conversion method: 1, use the parseInt () function to convert the string to decimal number, syntax "parseInt (" string ")"; 2, use toString () function to convert decimal number to octal number, syntax "decimal number .toString (8)".

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

The method of converting string to octal by javascript

First use the parseInt () function to convert a string to a decimal number

Then use the toString () function to convert a decimal number to an octal number

Example:

Var str = "1254"; var num = parseInt (str); var x=num.toString (8); console.log (x)

Description:

1. ParseInt ()

ParseInt: convert strings to integers

ParseInt (string, radix)

The string to be parsed by string.

Optional. Represents the cardinality of the number to parse. The value is between 2 and 36.

If the parameter is omitted or its value is 0, the number is parsed on the basis of 10.

If it starts with "0x" or "0X", it will have a base of 16.

If the parameter is less than 2 or greater than 36, parseInt () returns NaN.

2. ToString ()

The toString () method belongs to the Object object, which is overridden by many of JavaScript's built-in objects to better suit its own functional needs.

The type behavior description Array converts each element of Array into a string and concatenates them in turn, concatenating the two elements with an English comma as a delimiter. Boolean returns "true" if the Boolean value is true. Otherwise, "false" is returned. Date returns a text representation of the date. Error returns a string containing the relevant error information. Function returns a string in the following format, where functionname is the name of a function whose toString method is called: "function functionname () {[native code]}" Number returns a string representation of the numeric value. You can also return a string in the specified base, please refer to Number.toString (). String returns the value of the String object. Object (default) returns "[object ObjectName]", where ObjectName is the name of the object type. The above is about the content of this article on "how to convert a string into octal in javascript". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report