当前位置:网站首页>Rounding related calculation
Rounding related calculation
2022-06-25 21:05:00 【Mr. Liu works hard】
Ah , Recently, it is because of a certain amount , Just a few customers , Let the development without internal confirmation , I have to change the amount back and forth , Okay . Give you some way to calculate the whole rounding .
1 Keep two decimal places toFixed(n)
Round function toFixed(), The parameters inside It's the number of decimal places .
let a=2.1512131231231321;
console.log(a.toFixed(2)) // 2.15
2 Keep only the integer parts ( Discard the fraction ) parseInt()
let a=2.1512131231231321;
console.log(parseInt(a)) // 2
3 Rounding down (<= The maximum integer of the value , and parseInt() equally )
let a=2.1512131231231321;
console.log(Math.floor(a)) // 2
4 Rounding up ( There are decimals , Integer part +1)
let a=2.1512131231231321;
console.log(Math.ceil(a)) // 3
5 rounding ( The fractional part )
let a=5.1234
console.log(Math.round(a)) // 5
let b = 5.6789
console.log(Math.round(b)) // 6
6 Take the absolute value
let b = -5.6789
console.log(Math.abs(b)) // 5.6789
7 Returns the larger of two numbers
Math.max(1,2); // 2
8 Returns the smaller of two numbers
Math.min(1,2); // 1
9 random number (0-1)
Math.random();

10 If you want random integers, just add a calculation method to them Math.random()*10
OK 了 , Welcome to correct .
边栏推荐
- Is it legal to open an account for flush stock trading software? Is it safe?
- very good
- Cvpr2021 collection of papers | cvpr2021 latest papers | cvpr2021 review results | cvpr2021 admission results
- js (1)
- Introduction to event flow, event capture, and event bubbling
- Live broadcast preview | front line experts invite you to talk: the value of data science enabling multiple application scenarios
- couldn‘t be accessed by user ‘_ apt‘
- Yolov4 improved version comes out! Yolov4 extended edition! Yolov4 launched scaled-yolov4: scaling cross stage partial network
- Desktop network error display red ×, Component failed to start
- Is it safe for qiniu school to open a securities account?
猜你喜欢

Xshell mouse configuration
Why doesn't anyone read your hard-working blog? Do you really understand the skills of framing, typesetting and drawing?
Chrome plugin installation

Insert and update each database
How to play one to many in JPA?
Great changes in the interaction between people and the digital world
![[buucry] sensor (Manchester code)](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[buucry] sensor (Manchester code)

Docker failed to remotely access 3306 after installing MySQL
Day 28/100 CI CD basic introductory concepts
The secret of metaktv technology of sound network: 3D space sound effect + air attenuation + vocal blur
随机推荐
OLED driver learning based on ssd1306 (I): SSD Chinese command table (handling)
1.1-mq visual client preliminary practice
The live registration is hot to start | the first show of Apache dolphin scheduler meetup in 2022!
Heavy update! Yolov4 latest paper! Interpreting yolov4 framework
Getting started and using postman
Chrome plugin installation
Insert and update each database
Leetcode daily [2022 - 02 - 17]
[phase 23] phased summary of spring recruitment practice (Alibaba cloud has OC)
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
Yunzhisheng atlas supercomputing platform: computing acceleration practice based on fluid + alluxio (Part 2)
Detailed explanation of unified monitoring function of multi cloud virtual machine
The latest promo! 1 minute to understand the charm of the next generation data platform
R language quantile autoregressive QAR analysis pain index: time series of unemployment rate and inflation rate
JS__ Inheritance mode, namespace, object enumeration__ Duyi
Illustration tcp/ip - Chapter 3 and 4 notes
Desktop network error display red ×, Component failed to start
Tencent music knowledge map search practice
Global netizens Yuanxiao created a picture of appreciating the moon together to experience the creativity of Baidu Wenxin big model aigc
[machine learning] machine learning from zero to mastery -- teach you to understand the principle of decision tree