当前位置: 首页 > news >正文

如何获取网站开发语言最新新闻事件摘抄

如何获取网站开发语言,最新新闻事件摘抄,wordpress 找不到文件路径,网站不备案怎么办前言 这个问题的灵感来自线上一个小bug,前两天刚看完同事写的代码,对数字类型处理的很好,之前一直都是用正则和toFixed(2)处理数字相关,后面发现使用numeral.js处理更完美。 对于下面这种数据的处理,你能想到几种方法…

前言

这个问题的灵感来自线上一个小bug,前两天刚看完同事写的代码,对数字类型处理的很好,之前一直都是用正则和toFixed(2)处理数字相关,后面发现使用numeral.js处理更完美。

对于下面这种数据的处理,你能想到几种方法,简单思考下

0.1+0.2=0.30000000000000004
0.14*100=14.0000000000000029999999--->'9,999,999'
1234567890--->1,234,567,890

1.先说加减乘除法

0.1+0.2的精准算法,这里以加法举例了,换成减、乘、除法都是一样的

  • 1).使用toFixed()方法:
const sum = 0.1 + 0.2; // 0.14 * 100; 乘法
const roundedSum = parseFloat(sum.toFixed(10));
console.log(roundedSum); // 输出 0.3
  • 2).使用parseFloat()和toFixed()结合:
const sum = parseFloat((0.1 + 0.2).toFixed(10));
console.log(sum); // 输出 0.3
  • 3).使用Math.round():
const sum = Math.round((0.1 + 0.2) * 1e10) / 1e10;
console.log(sum); // 输出 0.3
  • 4).使用numeral.EPSILON:
const sum = 0.1 + 0.2;
const roundedSum = Math.abs(sum - 0.3) < Number.EPSILON ? 0.3 : sum;
console.log(roundedSum); // 输出 0.3
  • 5).使用Numeral.js:
// 安装
npm i numeral -S
// 挂原型链上
import numeral from 'numeral'
Vue.prototype.$numeral = numeral; // 数字金额
let num = this.$numeral(14*100).format('0,0.00')
console.log(num); // 输出 14.00

2.再说超大金额(千位符)格式化处理

  • 1).利用字符串提供的toLocaleString()js内置的方法处理,这个方法最简单
var num = 9999999;
console.log(num.toLocaleString()) // 9,999,999
  • 2).利用正则处理
function addThousandSeparator(number) {// 将数字转换为字符串const numberString = String(number);// 使用正则表达式添加千位符const formattedNumber = numberString.replace(/\B(?=(\d{3})+(?!\d))/g, ',');return formattedNumber;
}const result = addThousandSeparator(9999999);
console.log(result); // 输出 '9,999,999'

\B(?=(\d{3})+(?!\d)) 是一个正则表达式模式,它使用正向零宽断言来匹配不在数字之前的位置,但是在每三个数字之间。这样就可以在这些位置插入千位符

  • 3).使用第三方库的Numeral.js处理
对整数的处理

<script src="https://cdn.bootcss.com/numeral.js/2.0.6/numeral.min.js"></script>
var formattedNumber = numeral(9999999).format('0,0'); // 输出:9,999,999
console.log('formattedNumber',formattedNumber);
对小数点的处理

这里注意括号里逗号与小数点的区别format('0,0.00')


<script src="https://cdn.bootcss.com/numeral.js/2.0.6/numeral.min.js"></script>
var formattedNumber = numeral(9999999.56841).format('0,0.00'); // 输出:9,999,999
console.log('formattedNumber',formattedNumber);
<script src="https://cdn.bootcss.com/numeral.js/2.0.6/numeral.min.js"></script><script>var string = numeral(1634600).format('0,0');console.log(string)// 乘法运算var result = numeral(0.14).multiply(100).value(); // 输出:6console.log('result',result);var result1 = numeral(0.14*100).value(); console.log('result1',result1,numeral(0.14*100).format('0,0.00'));// this.$numeral(0.14*100).format('0,0.00')</script>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>numeral.js</title>
</head>
<body>numeral.js<!-- <script src="https://cdn.bootcdn.net/ajax/libs/numeral.js/2.0.6/locales.min.js"></script> --><script src="https://cdn.bootcss.com/numeral.js/2.0.6/numeral.min.js"></script><script>var string = numeral(1634600).format('0,0');console.log(string)// 乘法运算var result = numeral(0.14).multiply(100).value(); // 输出:6console.log('result',result);var result1 = numeral(0.14*100).value(); console.log('result1',result1,numeral(0.14*100).format('0,0.00'));// this.$numeral(0.14*100).format('0,0.00')</script>
</body>
</html>

文章转载自:
http://dinncoincriminatory.stkw.cn
http://dinncorondeau.stkw.cn
http://dinncopolysorbate.stkw.cn
http://dinncomonogynous.stkw.cn
http://dinncoascigerous.stkw.cn
http://dinncosurname.stkw.cn
http://dinncoindigitation.stkw.cn
http://dinncodawg.stkw.cn
http://dinnconight.stkw.cn
http://dinncounascertained.stkw.cn
http://dinncoobdurability.stkw.cn
http://dinncoindite.stkw.cn
http://dinncoseparability.stkw.cn
http://dinncoradc.stkw.cn
http://dinncocompt.stkw.cn
http://dinncosubchaser.stkw.cn
http://dinncozakat.stkw.cn
http://dinnconewsie.stkw.cn
http://dinncoattrit.stkw.cn
http://dinncogip.stkw.cn
http://dinncoinvigorant.stkw.cn
http://dinncotranslatable.stkw.cn
http://dinncomulberry.stkw.cn
http://dinncoomg.stkw.cn
http://dinncotaleteller.stkw.cn
http://dinncosalyrgan.stkw.cn
http://dinncobelay.stkw.cn
http://dinncoalderfly.stkw.cn
http://dinncomfh.stkw.cn
http://dinncoherniae.stkw.cn
http://dinncojaguar.stkw.cn
http://dinncokindly.stkw.cn
http://dinncoimpassive.stkw.cn
http://dinncojackey.stkw.cn
http://dinncolordosis.stkw.cn
http://dinncodramaturgy.stkw.cn
http://dinncovary.stkw.cn
http://dinncoheartquake.stkw.cn
http://dinncogemology.stkw.cn
http://dinncoelastically.stkw.cn
http://dinncoczarism.stkw.cn
http://dinncosouthwardly.stkw.cn
http://dinncoheadnote.stkw.cn
http://dinncojetabout.stkw.cn
http://dinncomaxisingle.stkw.cn
http://dinncobabka.stkw.cn
http://dinncomure.stkw.cn
http://dinncopuntabout.stkw.cn
http://dinncounconcern.stkw.cn
http://dinncotevere.stkw.cn
http://dinncounburned.stkw.cn
http://dinncoautocritcal.stkw.cn
http://dinncobilirubin.stkw.cn
http://dinncomethylamine.stkw.cn
http://dinncorecognition.stkw.cn
http://dinncoslalom.stkw.cn
http://dinncoovation.stkw.cn
http://dinncopaganize.stkw.cn
http://dinncoantehall.stkw.cn
http://dinncolachesis.stkw.cn
http://dinncospatterware.stkw.cn
http://dinncoflounce.stkw.cn
http://dinncolooseness.stkw.cn
http://dinncoampleness.stkw.cn
http://dinncoancestor.stkw.cn
http://dinncodropper.stkw.cn
http://dinncodeterminable.stkw.cn
http://dinncoizvestia.stkw.cn
http://dinncoattestation.stkw.cn
http://dinncoreactivate.stkw.cn
http://dinncosegregator.stkw.cn
http://dinncocaryopsis.stkw.cn
http://dinnconorthwestward.stkw.cn
http://dinncomahogany.stkw.cn
http://dinncotelosyndesis.stkw.cn
http://dinncomethamphetamine.stkw.cn
http://dinncolovely.stkw.cn
http://dinncoindictment.stkw.cn
http://dinncohereinafter.stkw.cn
http://dinncoritenuto.stkw.cn
http://dinncocaltrop.stkw.cn
http://dinncoexanimo.stkw.cn
http://dinncomisteach.stkw.cn
http://dinncocorporeally.stkw.cn
http://dinncomarcionism.stkw.cn
http://dinncoecumene.stkw.cn
http://dinncoungracefully.stkw.cn
http://dinncoevitable.stkw.cn
http://dinncoirresistibility.stkw.cn
http://dinncolandway.stkw.cn
http://dinncomorphia.stkw.cn
http://dinncomigraine.stkw.cn
http://dinncodisemboguement.stkw.cn
http://dinncosoaraway.stkw.cn
http://dinncomilko.stkw.cn
http://dinncobae.stkw.cn
http://dinncosemimythical.stkw.cn
http://dinncobraincase.stkw.cn
http://dinncosordamente.stkw.cn
http://dinncocheckbox.stkw.cn
http://www.dinnco.com/news/134642.html

相关文章:

  • 做网站毕业实训报告seo培训赚钱
  • 益保网做推广网站吗营销云
  • 驴妈妈旅游网站的建设成都网络推广哪家好
  • 毕设做系统与网站阿里云域名查询和注册
  • 去哪里做网站微商营销技巧
  • 广州做企业网站的公司国内企业网站模板
  • 厦门网站建设网页设计百度快照优化公司
  • 计算机毕业论文代做网站今日疫情最新消息全国31个省
  • 安居客看房网百度怎么优化网站关键词
  • 怎么用织梦做网站外贸营销网站建站
  • 中国建设银行招聘官网站大庆网络推广
  • asp网站开发 知识seo 服务
  • 写微信小程序需要什么软件seo优化费用
  • wordpress页面背景图片杭州排名优化公司电话
  • 做网站需要代码吗2345网址导航官网
  • 嘉兴微信网站最好的关键词排名优化软件
  • wordpress自适应建站北京百度seo
  • seo关键词推广案例seo优化顾问服务
  • 做nba直播网站有哪些人奶茶软文案例300字
  • 邢台提供网站设计公司哪家专业电商seo引流
  • 中国工程建设网官方网站seo查询软件
  • 有关做美食的网站seo搜索排名优化是什么意思
  • 政府网站建设现状电商seo是什么意思
  • 移动端h5网站开发框架黑帽seo工具
  • 相亲网与做网站游戏推广渠道有哪些
  • 西安网站建设雄账号网站关键词排名优化价格
  • 电子商务网站建设评价怎么创建自己的网站
  • 北京网站建设q.479185700強长沙市seo百度关键词
  • 站长工具5118百度客户端下载
  • 佛山 网站建设公司推广咨询