Skip to Content
JavaScript 经典实例:第三版
book

JavaScript 经典实例:第三版

by Adam D. Scott, Matthew MacDonald, Shelley Powers
September 2022
Intermediate to advanced
585 pages
8h 17m
Chinese
China Electric Power Press Ltd.
Content preview from JavaScript 经典实例:第三版
数字
87
console.log(num.toString(16));
3.6.3
讨论
默认情况下,
JavaScript
中的数字使用基数
10
,即十进制。不过,数字也可以转换
成其他基数,包括十六进制和八进制。十六进制数以
0x
(一个零后跟一个小写字母
x
开头。八进制数以前仅以一个零(
0
)开头,但是现在应该以一个零后跟一个拉丁字
O
(大小写均可)开头。
const
octalNumber = 0o255; //
等同于十进制数
173
const
hexaNumber = 0xad; //
等同于十进制数
173
十进制数可以转换成其他基数,从
2
36
均可。
const
decNum = 55;
const
octNum = decNum.toString(8); //
八进制数
67
const
hexNum = decNum.toString(16); //
十六进制数
37
const
binNum = decNum.toString(2); //
二进制数
110111
为了完整表示八进制和十六进制数,要在八进制数前加上
0o
,在十六进制数前加上
0x
。不过请记住,把数字转换成字符串之后,不管格式如何,在任何进行数值计算
的地方都不能使用。
虽然十进制数可以转换成任何基数(范围为
2
36
),但是只有八进制、十六进制
和十进制数可以直接作为数字处理。
3.7
角度和弧度互相转换
3.7.1
问题
你有一个使用角度度量的角。为了在
Math
对象的三角函数中使用这个值,你要把角
度转换为弧度。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript

JavaScript

T. J. Crowder
JavaScript

JavaScript

David Flanagan
JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov

Publisher Resources

ISBN: 9787519869601