菜单
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

JS 参考手册

按类别划分的 JS 按字母划分的 JS

JavaScript

JS 数组 JS 布尔值 JS 类 JS 日期 JS 错误 JS 全局 JS JSON JS Map JS Math JS 数字 JS 对象 JS 运算符 JS 优先级 JS Promise JS 正则表达式 JS Set JS 语句 JS 字符串 JS TypedArray

Window

Window 对象 Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

HTML 文档 HTML 元素 HTML 属性 HTML 集合 HTML NodeList HTML DOMTokenList HTML 样式
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundClip backgroundColor backgroundImage backgroundOrigin backgroundPosition backgroundRepeat backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cssFloat cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

HTML 事件

HTML 事件 HTML 事件对象 HTML 事件属性 HTML 事件方法

Web API

API Canvas API Console API Fetch API Fullscreen API 地理位置 API History API MediaQueryList API Storage API 验证 API Web

HTML 对象

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

其他参考

CSSStyleDeclaration JS 转换


JavaScript Number toLocaleString()

示例

使用区域设置将数字格式化为字符串

let num = 1000000;
let text = num.toLocaleString();
自己动手试一试 »

使用芬兰的特定区域设置将数字格式化为字符串

let num = 1000000;
let text = num.toLocaleString("fi-FI");
自己动手试一试 »

使用美国特定的区域设置将数字格式化为货币字符串

let num = 1000000;
let text = num.toLocaleString("en-US", {style:"currency", currency:"USD"});
自己动手试一试 »

更多示例见下文


描述

toLocaleString() 使用本地语言格式将数字作为字符串返回。

语言格式取决于您计算机上的区域设置。


语法

number.toLocaleString(locales, options)

参数

参数 描述
地区

试一试
可选。
要使用的特定语言格式。
点击“尝试一下”按钮查看所有值。

ar-SA 阿拉伯语(沙特阿拉伯)
bn-BD 孟加拉语(孟加拉国)
bn-IN 孟加拉语(印度)
cs-CZ 捷克语(捷克共和国)
da-DK 丹麦语(丹麦)
de-AT 奥地利德语
de-CH “瑞士”德语
de-DE 标准德语(德国使用)
el-GR 现代希腊语
en-AU 澳大利亚英语
en-CA 加拿大英语
en-GB 英国英语
en-IE 爱尔兰英语
en-IN 印度英语
en-NZ 新西兰英语
en-US 美国英语
en-ZA 英语(南非)
es-AR 阿根廷西班牙语
es-CL 智利西班牙语
es-CO 哥伦比亚西班牙语
es-ES 卡斯蒂利亚西班牙语(西班牙中北部使用)
es-MX 墨西哥西班牙语
es-US 美式西班牙语
fi-FI 芬兰语(芬兰)
fr-BE 比利时法语
fr-CA 加拿大法语
fr-CH “瑞士”法语
fr-FR 标准法语(尤其在法国)
he-IL 希伯来语(以色列)
hi-IN 印地语(印度)
hu-HU 匈牙利语(匈牙利)
id-ID 印度尼西亚语(印度尼西亚)
it-CH “瑞士”意大利语
it-IT 标准意大利语(意大利使用)
ja-JP 日语(日本)
ko-KR 韩语(韩国)
nl-BE 比利时荷兰语
nl-NL 标准荷兰语(荷兰使用)
no-NO 挪威语(挪威)
pl-PL 波兰语(波兰)
pt-BR 巴西葡萄牙语
pt-PT 欧洲葡萄牙语(葡萄牙书写和口语)
ro-RO 罗马尼亚语(罗马尼亚)
ru-RU 俄语(俄罗斯联邦)
sk-SK 斯洛伐克语(斯洛伐克)
sv-SE 瑞典语(瑞典)
ta-IN 印度泰米尔语
ta-LK 斯里兰卡泰米尔语
th-TH 泰语(泰国)
tr-TR 土耳其语(土耳其)
zh-CN 中国大陆,简体字
zh-HK 香港,繁体字
zh-TW 台湾,繁体字

选项 可选。
包含格式选项的对象

货币 合法值:任何货币代码(如“EUR”、“USD”、“INR”等)
货币显示
合法值
"symbol"(默认)
“code”
“name”
区域设置匹配器
合法值
"best-fit"(默认)
“lookup”
最大小数位数
0 到 20 之间的一个数字(默认值为 3)
最大有效位数
1 到 21 之间的一个数字(默认值为 21)
最小小数位数
0 到 20 之间的一个数字(默认值为 3)
最小整数位数
1 到 21 之间的一个数字(默认值为 1)
最小有效位数
1 到 21 之间的一个数字(默认值为 21)
样式
合法值
“currency”
"decimal"(默认)
“percent”
使用分组
合法值
"true"(默认)
“false”

返回值

类型 描述
一个字符串表示本地格式数字的字符串。


更多示例

使用 options 参数(对象)进行货币格式化

let num = new Number(1000000);
const myObj = {
  style: "currency",
  currency: "EUR"
}
let text = num.toLocaleString("en-GB", myObj);
自己动手试一试 »
let num = new Number(1000000);
let text = num.toLocaleString("en-GB", {style:"currency", currency:"EUR"});
自己动手试一试 »

使用日本的特定区域设置

let num = 1000000;
let text = num.toLocaleString("ja-JP", {style:"currency", currency:"JPY"});
自己动手试一试 »

浏览器支持

toLocaleString() 是 ECMAScript3 (ES3) 的一个特性。

ES3 (JavaScript 1999) 在所有浏览器中都得到完全支持

Chrome Edge Firefox Safari Opera IE

浏览器支持

(locales, options) 在所有现代浏览器中都受支持

Chrome Edge Firefox Safari Opera IE
11

×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持