JavaScript Math and Number object research

Source: Internet
Author: User
Tags abs instance method natural logarithm pow square root value of pi

1. Math Object

1.1 Introduction   Math object is a mathematical object that provides mathematical calculations of the data, such as obtaining absolute values, rounding up, and so on. No constructors, cannot be initialized, only static properties and methods are provided.  1.2 Constructors   None: The Math object has no constructors, cannot be initialized, and only provides static properties and methods.  1.3 static Property  1.3.1 MATH.E: Constant E. Returns the base of the natural logarithm: 2.718281828459045 1.3.2 Math.PI: Constant π. Returns the value of pi: 3.141592653589793 1.4 static method  1.4.1 Math.sin (value): sine function 1.4.2 Math.Cos (value): cosine function 1.4.3 Math.tan ( Value): Tangent function 1.4.4 Math.asin (value): Inverse sine function 1.4.5 math.acos (value): Inverse cosine function 1.4.6 Math.atan (value): Inverse tangent function      1.4.7 Math.Abs (value): Returns the absolute value parameter:  ①value {number | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {number} returns the absolute number of the parameter. If the argument is not a number, the Nan is returned.   Example:   h.abs (' 123 '); = 123: Pure numeric string Math.Abs ('-123 '); = 123math.abs (123); = 123math.abs (-123); = = 123math.abs (' 123a '); = = NaN: Non-pure numeric string  1.4.8  math.ceil (value): Rounding a number up, not rounding argument:  ①value {# | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {number} returns the value after rounding. If the argument is not a number, the Nan is returned.   Example:   math.ceil (2.7); = 3math.ceil (2.3); = 3:2.3 toRounding up returns 3math.ceil (-2.7); = -2math.ceil (-2.3); = = -2math.ceil (' 2.7 '); = 3: Pure numeric string Math.ceil (' 2.7a '); = = NaN: Non-pure numeric string   1.4.9 Math.floor (value): Rounding a number down, not rounding argument:  ①value {# | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {number} returns the value after rounding. If the argument is not a number, the Nan is returned.   Example:  math.floor (2.7); = 2math.floor (2.3); = 2math.floor (-2.7); = 3:-2.7 Rounding down returns -3math.floor (-2.3); = = -3math.floor (' 2.7 '); = 2: Pure numeric string Math.floor (' 2.7a '); = = NaN: Non-pure numeric string   1.4.10 Math.max (Value1,value2...valuen): Returns the largest value parameter in the parameter:  ①value1,value2 ... Valuen {Number | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {number} returns the maximum value. If a parameter is not a number, the Nan is returned.   Example:   math.max (1, 2, 3, 4, 5); = = 5math.max (1, 2, 3, 4, ' 5 '); = = 5math.max (1, 2, 3, 4, ' a '); = = NaN  1.4.11 math.min (Value1,value2...valuen): Returns the smallest value parameter in the parameter:  ①value1,value2.....valuen {number | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {number} returns the maximum value. If a parameter is not a number, the Nan is returned.   Example:   math.min (1, 2, 3, 4, 5); = = 1math.min (' 1 ', 2, 3, 4, 5); = = 1math.min (1, 2, 3, 4, ' a '); = = nan  1.4.12 Math.pow (x, y): Returns the Y-square parameter of x:  ①x {number | NUMBERSTR}: A string of numbers or pure numbers.  ②y {Number | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {number} returns the Y-side of X. If a parameter is not a number, the Nan is returned.   Example:  math.pow (2, 3); = 8:2 of 3 square Math.pow (3, 2); = 9:3 of 2 square math.pow (' 4 ', 2); = 16:4 of 2 square math.pow (' 2a ', 2); = nan  1.4.13 Math.random (): Returns a pseudo-random number, greater than 0, less than 1.0 parameters: None   return value:  {number} returns a pseudo-random number greater than 0, less than 1.0   Example:  math.random (); = 0.8982374747283757math.random (); = 0.39617531932890415math.random (); = 0.35413061641156673math.random (); = = 0.054441051790490746  1.4.14 Math.Round (value): Rounding parameter:  ①value {number | NUMBERSTR}: A string of numbers or pure numbers.   return value:  {integer} returns the integer after the parameter is rounded. If the argument is not a number, the Nan is returned.   Example:   math.round (2.5); = 3math.round (2.4); = 2math.round (-2.6); = -3math.round (-2.5); =-2:-2.5 rounded to -2math.round (-2.4); = = -2math.round (' 2.7 '); = 3: Pure numeric string Math.Round (' 2.7a '); = = NaN: Non-pure numeric string   1.4.15 math.sqrt (value): Returns the square root parameter of the parameter:  ①value {number | NUMBERSTR}: Numeric or purely numeric string   return value:  {number} returns the square root of the parameter   example:   console.log (MATH.SQRT (9)); = 3console.log (Math.sqrt (16)); = = 4console.log (math.sqrt (' 25 ')); = = 5console.log (math.sqrt (' a ')); = = Nan  2. The Number object 2.1 describes the   numbers object, which is a numeric object that contains integers in JS, floating-point numbers, and so on.  2.2 definition   var a = 1;var B = 1.1;2.3 static property  2.3.1 Number.MAX_VALUE: Represents the largest number in JS, about 1.79e+308 2.3.2 Num ber. Min_value: Represents the smallest number in JS, approximately 5e-324 2.3.3 Number.NaN: Returns Nan, representing a non-numeric value, ranging from any other number, and also including the NaN itself. Number.isnan () should be used for judgment.  2.3.4 number.negative_infinity: Returns-infinity, which indicates negative infinity.  2.3.5 number.positive_infinity  : Returns INFINITY, indicates positive infinity. The value that is calculated is greater than Number.MAX_VALUE and returns Infinity.  2.4 static method  2.4.1 Number.isinteger (value): Determines whether the parameter is an integer   parameter:  ①value {Number}: Numeric   return value:  {boolean} returns whether the parameter is an integer. A string of pure integers also returns false.   Example:   number.isinteger (1); = Truenumber.isinteger (1.1); = = Falsenumber.isinteger (' 1 '); = = False: A string of pure integers also returns Falsenumber.isinteger (' 1.1 '); = = Falsenumber.isinteger (' a '); = = false: Non-string returns false  2.4.2 Number.isnan (value): Determines whether the parameter is a nan parameter:  ①value {Object}: Any type   return value: & nbsp {Boolean} returns whether the parameter is Nan.   Example:   number.isnan (NaN); = = Truenumber.isnan (' NaN '); = = false: ' NaN ' string, not Nannumber.isnan (1); = = Falsenumber.isnan (' 1 '); = = false  2.4.3 Number.parsefloat (value): Converts a parameter to a floating-point parameter:  ①value {number | NUMBERSTR}: String   Return value of a number or a pure number:  {integer | FLOAT} returns an integer or floating-point number value   Example:   number.parsefloat (1); = 1: Integer or return integer number.parsefloat (1.1); = = 1.1number.parsefloat (' 1aaa '); = 1: String preceded by a number, only returns the number Number.parsefloat (' 1.1aaa '); = = 1.1number.parsefloat (' A1 '); = = NaN: Non-numeric start, return nannumber.parsefloat (' a '); = = nan  2.4.4 Number.parseint (value): Converts the argument to an integer parameter:  ①value {number | NUMBERSTR}: Numeric or purely numeric string   return value:  {integer} returns an integer value   example:   number.parseint (1); = 1number.parseint (1.1); + 1: Floating-point numbers return integer number.parseint (' 1aaa '); = 1: String preceded by a number, only returns the number Number.parseint (' 1.1aaa '); = = 1number.parseint (' A1 '); = = NaN: Non-numeric start, return Nannumber.parseint (' a '); = = nan  2.5 Instance method  2.5.1 toexponential (value): Converts a number to an exponential type, the parameter represents the number of digits after the decimal point parameter:  ①value {#}  : represents the number of digits after the decimal point   return value:  {string} returns the converted exponential type string   example:  (123456789). toexponential (2); = 1.23e+8: Decimal 2 bits (123456789). toexponential (5); = 1.23457e+8: decimal 5 bits (123456789). toexponential (10); + 1.2345678900e+8: decimal 10 digits, insufficient digits with 0 complement   2.5.2 toFixed (value): Converts a number to a string of the specified number of decimal places. Does not pass in the parameter, is not the decimal place. The return value is the rounding parameter:  ①value {number}  : Represents the digits after the decimal point   return value:  {string} returns the converted string, not enough decimal places to fill with 0; return value is rounded value   Example:   console.log ((1). toFixed (2)); = 1.00consolE.log ((1.2). ToFixed (2)); + 1.20: Insufficient digits, with 0 complement Console.log ((1.277). toFixed (2)); = 1.28: Rounding   2.5.3 toString (): Converts a number to a string using the specified binary. The parameter is not passed in, and the default is decimal. Parameters:  ①value {number}  : Represents the binary Value range: 2 to 36  return value:  {string} Convert Backward string   example:   (10). ToString (); = 10: The default is decimal (Ten). toString (2); = 1010: Binary (Ten). toString (10); + 10: Decimal (Ten). toString (16); + A: Hex  2.6 scenario  2.6.1 floating Point Subtraction exception description: JS 2 Floating-point number for the subtraction operation, will return the value of the exception, such as: 0.2+0.7, return 0.899999999999. You can use the tofixed () method to specify decimal digits.   Example:   console.log (0.2 + 0.7); = 0.8999999999999999console.log (0.7-0.5); = 0.19999999999999996console.log (3.03 * 10); = = 30.299999999999997 //Use the toFixed () method Console.log ((0.2 + 0.7). ToFixed (2)); = 0.90console.log ((0.7-0.5). toFixed (2)); = 0.20 console.log ((3.03 *). ToFixed (2)); = = 30.30  2.6.2 subtraction operation Description: JS in the subtraction operation, the value of the front and back will be converted to a value before the operation. If the conversion fails, a Nan is returned.   Example:   console.log (' 1 '-0); => 1: Pure numeric string minus 0, can be quickly converted to Nubmer object Console.log ((' 1 '-0). toFixed (2)); + 1.00: Call instance method Console.log (' 1 '-' a ') after fast conversion to Nubmer object; = = NaN: One party cannot convert to a Nubmer object

JavaScript Math and Number object research

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.