web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

javaScript数字格式化方法介绍

771 ℃
     

功能介绍:利用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有哪些方法可以实现继承

web前端中head中常用的标签有哪些?

javascript三元运算符是什么?(常用语法介绍)

介绍几种对象转换为数组的javascript方法

js创建一个指定长度数组(根据数字显示数组长度)

标签: JavaScript方法, script, 数字, 数字格式化

上面是“javaScript数字格式化方法介绍”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2346.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计1716个字,预计阅读时长12分钟
生活小工具,收录了80多款小工具
上一篇: 基于JavaScrip的web动画库——GSAP
下一篇: 免费商用中文字体——优设鲨鱼菲特健康体
x 打工人ai神器