开发者

JavaScript - opposite of toString()?

开发者 https://www.devze.com 2023-02-03 08:24 出处:网络
When used with numbers, the toString() method converts a number into a string representation using the base numbering system specified by the optional radix.

When used with numbers, the toString() method converts a number into a string representation using the base numbering system specified by the optional radix.

For instance the number 8 and toString(2) would return "1000".

Is there a method to achieve the opposite? I.e., convert the string "1000" back into the n开发者_Go百科umber 8?


parseInt() takes a radix as its second argument, so you can do parseInt("1000", 2) to get what you want.


You can use parseInt using a raidx 2. i.e

parseInt("1000", 2) will return 8


Check the parseInt() Javascript function: http://www.w3schools.com/jsref/jsref_parseInt.asp

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号