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

barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
纯html+css做一个3d统计效果
HTML5 Canvas 刻度尺
黑客入侵效果代码
iframe开发admin后台
css3结合svg做一个动态广告
canvas黑洞漩涡(canvas+js)
Bootstrap可视化拖放布局











