vue实现数字千分位格式化 如6,383,993,037,937.463

1.封装文件:numberToCurrency.js

复制代码
/**实现数字千分位格式化 如6,383,993,037,937.463 */
export function numberToCurrencyNo(value) {
  if (!value) return 0
  // 获取整数部分
  const intPart = Math.trunc(value)
  // 整数部分处理,增加,
  const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  // 预定义小数部分
  let floatPart = ''
  // 将数值截取为小数部分和整数部分
  const valueArray = value.toString().split('.')

  if (valueArray.length === 2) { // 有小数部分
    floatPart = valueArray[1].toString() // 取得小数部分
    return intPartFormat + '.' + floatPart.slice(0,2)
  }
  return intPartFormat + floatPart
}

2.在index.vue引用

复制代码
<template>
  <div>
      <--页面引用-->
    {{ numberToCurrencyNo(6383993037937.463) }}
  </div>
</template>


import { numberToCurrencyNo } from "@/numberToCurrency.js"; //千分位格式化

//js中使用
mounted(){
let dataNew = '6383993037937.463'
  dataNew=numberToCurrencyNo(data);
},
相关推荐
默_笙11 小时前
🚦 请三个 AI 考官给 RAG 打分:量化评估实战(下)
前端·javascript
阿坨11 小时前
灵感闪存卡:一款 Tampermonkey用户脚本
javascript·tampermonkey
朝朝辞暮i13 小时前
C++ 第 25 课:getter / setter + this
java·javascript·c++
蜗牛互联网13 小时前
Python接入Gemini 3.8 Flash实现票据视觉抽取与规则校验
java·javascript·网络·人工智能·python
易朵朵14 小时前
CSS 格式化上下文
css·vue.js
xieter14 小时前
【技术精选】深入浅出现代前端渲染与性能优化实践指南 (2026-10-04)
前端·javascript
xieter14 小时前
【硬核实战】TypeScript Compiler API: Preserving Child Node Narrowing in Reusable Type Guards 🔧 (2026-10-03)
前端·javascript
xieter14 小时前
【硬核实战】React 19 useFormStatus Returning False? I Built a SubmitButton That Fixes It (2026-10-03)
前端·javascript
雪芽蓝域zzs15 小时前
第6节:远程搜索弹窗(remote 模式),弹窗滚动加载分页
vue.js·elementui
paopaokaka_luck16 小时前
非遗文物数字化小程序(AI非遗问答、ONNX图像识别、协同过滤推荐、ECharts数据分析、非遗知识浏览与互动、文创商城订单闭环、文化活动报名签到、社区交流)
javascript·spring boot·mysql·数据分析·echarts·mybatis