功能介绍:利用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工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3卡片动态滑动效果
利用css绘画棋盘布局(象棋)
css3+js菜单点击动态效果
自动打字效果(惊喜在后面)
Bootstrap可视化拖放布局
数字滚动效果(兼容IE6/IE8)
css3做一个风雨雷电天气动态图标
html5如何3D立方体旋转特效







