当前位置:网站首页>JS takes two decimal places
JS takes two decimal places
2022-06-23 20:34:00 【It workers】
We need to keep two decimal places , have access to toFixed Method , But some numbers are Unwanted With two decimal places .
For example, the following two variables
/** * Rhinoceros front tribe */ var a = 1.777; var b = 1.6;
Variable a The decimal point of exceeds 2 position , We can use toFixed To achieve .
a.toFixed(2); // Output 1.78
But variables b There is only one digit after the decimal point , We may not need to implement two decimal places , If you use toFixed There will be Ambiguity , for example :
b.toFixed(2);// Output 1.70
terms of settlement
We can use some mathematical skills , For example, the following implementation method :
Math.round( Variable *100)/100;
Take the example above , Execute the above formula , Will return the result we want :
/** * Rhinoceros front tribe */ var a = 1.777; var b = 1.6; Math.round(a*100)/100; //1.78 Math.round(b*100)/100; //1.6
Above we have realized the method of keeping two decimal places , I hope I can sum up the way , It works for you .
边栏推荐
- How to write a great online user manual in 7 steps
- TCP/UDP基本原理
- SAP实施项目上的内部顾问与外部顾问,相互为难还是相互成就?
- Is Guoyuan futures trading software formal? How to download safely?
- 徽商期货交易软件正规吗?如何安全下载?
- Crise de 35 ans? Le volume intérieur est devenu synonyme de programmeur...
- Open source SPL redefines OLAP server
- Shell Scripting
- LeetCode 260. Number III that appears only once
- [golang] quick review guide quickreview (VIII) -- goroutine
猜你喜欢

Tcp/udp Fundamentals

八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?

GL Studio 5 安装与体验

Open source SPL redefines OLAP server

图扑软件数字孪生智慧水务,突破海绵城市发展困境

ElastricSearch第二弹之分片原理

Kubernetes resource topology aware scheduling optimization

官宣.NET 7 预览版5

Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181

「开源摘星计划」Containerd拉取Harbor中的私有镜像,云原生进阶必备技能
随机推荐
Kinsoku jikou desu新浪股票接口变动
Can Tencent cloud disk service share data? What are the advantages of cloud disk service?
【Golang】跟着源码学技巧系列之对象池sync.Pool
重庆 奉节耀奎塔,建成后当地连中五名进士,是川江航运的安全塔
How to build Tencent cloud game server? Differences between cloud game platforms and ordinary games
小程序开发框架推荐
The golden nine silver ten, depends on this detail, the offer obtains the soft hand!
[golang] delving into strings -- from byte run string to unicode and UTF-8
Implementation of microblog system based on SSM
LeetCode 260. Number III that appears only once
CPS 22 January additional incentive rules
Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation
科班出身,结果外包都不要
Real topic of the 13th National Competition of single chip microcomputer in the Blue Bridge Cup
[vernacular technology] QR code
35 year old crisis? It has become a synonym for programmers
Why is only one value displayed on your data graph?
[golang] quick review guide quickreview (VII) -- Interface
技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
Emmet syntax specification