<>JavaScript study Lesson Two ( two )

one ,Math object :

This object is used to handle mathematical operators , The object does not need to be created manually , Because it is window Object , When the page is loaded , The background is created automatically Math object , It can be used window.Math Ali use . Or omit window object , Direct use Math.

two ,Math Common properties of —PI
1, effect : Get pi
2, format :Math.PI

three ,Math The common methods to solve this problem

1),round method :
effect : Round the data
format : Math.round( data );
Return value : Returns the integer part of the data , That is to say, when rounding the data, the method is to process one digit after the decimal point .

2),ceil method :
effect : Round up the data , Take the smallest integer
format :Math.ceil( data );
Return value : The smallest integer larger than data

3)floor method :
effect : Round down the data , Take the largest integer
format :Math.floor( data );
4),random method :
effect : generate 0-1 Random number of , contain 0, But not included 1
format :Math.random();
be careful :
1): If you want to generate n-m, And include n and m Random integer of :
parseInt(Math.random()*( Maximum +1- minimum value )+ minimum value );
2): If you want to generate random subscripts of arrays or strings :
parseInt(Math.random() * array .length); console.log(Math.random());

5) ,max method :
effect ; Finding the maximum value of a set of data
format :Math.max( value 1, value 2, value 3…);

6),min method :

effect : Find the minimum value in a set of data
format :Math.min( value 1, value 2, value 3…);
console.log(Math.min(1, 2, 4, 7, 10)); console.log(Math.max(10, 4, 5, 90));

7),abs method :
effect : Finding the absolute value of data
format :Math.abs( value );
Return value : Absolute value of data ;

8),pow method

effect : seek x Of y Power
format :Math.pow(x,y);
console.log(Math.pow(2, 10));

9),sqrt method :
effect : Finding the arithmetic square root of data
format :Math.sqrt( data );

four ,toFixed method
effect : To process the number of decimal places of a data
format : data .toFixed( Number of decimal places );
be careful : The return value of this method is a string type
var num = Math.PI; var res = num.toFixed(3); console.log(res); console.log(
typeof res);

©2019-2020 Toolsou All rights reserved,
Hikvision - Embedded software written test questions C Language application 0 The length of array in memory and structure is 0 In depth analysis data structure --- The preorder of binary tree , Middle order , Subsequent traversal How to do it ipad Transfer of medium and super large files to computer elementui Shuttle box el-transfer Display list content text too long 2019 The 10th Blue Bridge Cup C/C++ A Summary after the National Games ( Beijing Tourism summary )unity Shooting games , Implementation of first person camera python of numpy Module detailed explanation and application case Study notes 【STM32】 Digital steering gear Horizontal and vertical linkage pan tilt Vue Used in Element Open for the first time el-dialog Solution for not getting element