当前位置:网站首页>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 .
边栏推荐
- 80% of people will be wrong about the three counter intuitive questions?
- [vernacular technology] QR code
- 国元期货交易软件正规吗?如何安全下载?
- CPS 22 January additional incentive rules
- What technology is used for video intelligent audit? Difficulties encountered in video audit?
- [golang] quick review guide quickreview (I) -- string
- 科班出身,结果外包都不要
- Syntaxe des requêtes fédérées SQL (inline, left, right, full)
- How to open a domestic futures account? Which futures company is safer to open an account?
- Implementation of microblog system based on SSM
猜你喜欢

Kubernetes resource topology aware scheduling optimization

FPGA based electromagnetic ultrasonic pulse compression detection system paper + source file

官宣.NET 7 预览版5

Tcp/udp Fundamentals

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

LeetCode 473. Match to square

测试的重要性及目的

Elastricearch's fragmentation principle of the second bullet

Eight misunderstandings, broken one by one (final): the cloud is difficult to expand, the customization is poor, and the administrator will lose control?

Rstudio 1.4 software installation package and installation tutorial
随机推荐
OHOS LTS 3.0移植到RaspberryPi 4B
The golden nine silver ten, depends on this detail, the offer obtains the soft hand!
How to open a domestic futures account? Which futures company is safer to open an account?
教你如何用网页开发桌面应用
Kotlin jetpack compose Tab的渲染 AnimatedVisibility的使用
What technology is used for video intelligent audit? Difficulties encountered in video audit?
5 月最大的 GameFi 崩溃受害者能否在熊市中生存?| May Monthly Report
[golang] some questions to strengthen slice
Ugeek's theory 𞓜 application and design of observable hyperfusion storage system
@@Script implementation of ishell automatic deployment
WinDbg loads mex DLL analysis DMP file
【Golang】类型转换归纳总结
【白话技术】二维码
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
35 year old crisis? It has become a synonym for programmers
[golang] quick review guide quickreview (VI) -- struct
String Day6 of Li Kou daily practice
Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation
20 provinces and cities announce the road map of the meta universe
Importance and purpose of test