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 经典实例:第三版
字符串和正则表达式
53
en-US
区域,这个对象添加逗号分隔符,但是不保留固定的小数位,也不添加货
币符号。
Intl.NumberFormat
对象支持很多选项。你可以改变负数的显示方式,可以设定最
小和最大位数,可以显示百分数,也可以选择某些语言中的其他编号系统。完整的
信息参阅
Mozilla Developer Network
参考手册(
https://oreil.ly/JEF4Q
)。
你可能会遇到区域设置的旧版写法,使用的是
Number.toLocaleString()
法。下
面举个例子。
const
someNumber = 1242.0005;
const
moneyString = someNumber.toLocaleString(
'en-US', { style: 'currency', currency: 'USD' });
这种方式完全有效,但是如果你打算格式化一长串数字,重用一个
Intl.
NumberFormat
对象的性能更好。
2.2.4
参考
如果你想获得的格式化支持
Intl.NumberFormat
提供的功能更多,可以使用第三
方库,例如
Numeral.js
https://github.com/adamwdraper/Numeral-js
)。
2.3
插入特殊字符
2.3.1
问题
你想在字符串中插入特殊字符,例如换行符。
2.3.2
方案
对很多特殊的字符来说,最简单的方法是直接把字符粘贴到编辑器中。比如说你需
要一个版权符号(
©
),首先在桌面实用程序,例如(
Windows ...
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