功能介绍:利用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工作流
一条精致透明的朱红色水晶龙
小孩手握锤子顽皮搞笑卡通3d形象
奇幻绘画风格:一只巨大蜗牛ComfyUI工作流
一位24岁的金发女海盗ComfyUI工作流
蝴蝶兰comfyui工作流
一只处于战斗状态下的蚂蚁ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用canvas画几个好玩的星云物种
用ascii字符画图像
纯css制作卡通头像(随鼠标转头)
利用css3做一个动态loading效果
canvas空间文本射线
css3结合svg做一个动态广告
canvas经线动画走到效果
css3做一个风雨雷电天气动态图标










