功能介绍:利用toLocaleString方法实现数字格式化。具体操作方法如下:
1、数字分割成千分位:
//默认显示千分逗号
var nums = 12345667890
nums.toLocaleString() //'12,345,667,890'
//useGrouping: false属性不显示千分逗号
var nums = 1234566789
nums.toLocaleString(undefined, {useGrouping: false}) //1234566789
2、保留几位小数
//保留最少小数minimumFractionDigits
var nums = 123456.6789
nums.toLocaleString(undefined, {minimumFractionDigits: 6}) //123,456.678900
//保留最多小数maximumFractionDigits
var nums = 123456.6789
nums.toLocaleString(undefined, {maximumFractionDigits: 2}) //123,456.68
3、使用的整数数字的最小数目minimumIntegerDigits
var nums = 123456.6789
nums.toLocaleString(undefined, {minimumIntegerDigits: 8}) //00,123,456.679
4、使用的有效数字的最小数目minimumSignificantDigits
var nums = 123456.6789
nums.toLocaleString(undefined, {minimumSignificantDigits: 8}) //123,456.6789
5. 使用的有效数字的最大数目maximumSignificantDigits
var nums = 123456.6789
nums.toLocaleString(undefined, {maximumSignificantDigits: 6}) //123,457
6、其他
//decimal: 纯数字
var nums = 123456.6789,
nums.toLocaleString(undefined, {style: 'decimal'}) //123,456.679
//percent:百分比
nums.toLocaleString(undefined, {style: 'percent'}) // 12,345,668%
//currency:用于货币格式
nums.toLocaleString(undefined, {style: 'currency', currency: 'EUR'}) // €123,456.68
nums.toLocaleString(undefined, {style: 'currency', currency: 'CNY'}) // ¥123,456.68
nums.toLocaleString(undefined, {style: 'unit', unit: 'acre'}) // 123,456.679英亩
nums.toLocaleString(undefined, {style: 'currency', currency: 'CNY', currencyDisplay: 'symbol'}) // ¥123,456.68
nums.toLocaleString(undefined, {style: 'currency', currency: 'CNY', currencyDisplay: 'code'}) // CNY 123,456.68
nums.toLocaleString(undefined, {style: 'currency', currency: 'CNY', currencyDisplay: 'name'}) // 123,456.68人民币
上面是“javaScript数字格式化方法介绍”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2346.html
workflows工作流
树上挂着一只表情可爱的香蕉ComfyUI工作流二
葡萄庄园白葡萄酒ComfyUI工作流
一个可爱的人形小机器人和一只蜗牛在森林
骨骼般的恶魔修女ComfyUI工作流
一条色彩斑斓的超现实小孔雀鱼ComfyUI工作流
一位身穿金色铠甲的美丽女子守卫在寺庙外
一支令人难忘的狙击步枪ComfyUI工作流
一只处于战斗状态下的蚂蚁ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

纯css3绘制的小鸟
利用CSS3做一个星级评分样式
如何利用css3+js做一个下雨效果
css3搭积木叠加图形
css3实现星球旋转
利用html5+css3实现滚雪球效果(附代码)
利用js+css3做一个小鱼游泳特效
一个包含老黄历、佛历、道历、星宿等数据的日历网站









