Home  >  Article  >  Web Front-end  >  Summary of Number methods in javascript

Summary of Number methods in javascript

高洛峰
高洛峰Original
2016-12-06 10:36:231056browse

1. Constructor

  Number(value)

  new Number(value)

2. Number attribute

  1. Number.MAX_VALUE Return the largest number that can be represented.

 2. Number.MIN_VALUE The smallest number that can be represented.

 3. Number.NAN  Non-numeric value.

 4. Number.NEGATIVE_INFINITY  Negative infinity, returned when overflows.

 5. Number.POSITIVE_INFINITY Positive infinity, returned when overflows.

3. Number method

 1. toString()  Use the specified base to convert a number into a string.

 2. toLocaleString() Convert a number to a string in local number format.

 3. toFixed() Convert a number to a string containing the specified number of decimal places.

 4. toExponential() Convert a number to a string, using the specified number of valid digits.

 5. valueOf()  Return the original value of a Number object.

 6. toExponential() Format a number using exponential notation

document.write(Number.MIN_VALUE + "<br/>");  //5e-324
document.write(Number.MAX_VALUE + "<br/>");  //1.7976931348623157e+308
document.write(Number.NaN + "<br/>");   //NaN
document.write(Number.NEGATIVE_INFINITY + "<br/>"); //-Infinity
document.write(Number.POSITIVE_INFINITY + "<br/>"); //Infinity
 
var num = Number(5.123);      //5.123
document.write(num.toString() + "<br/>");  //5.123
document.write(num.toFixed(2) + "<br/>");  //5.123
document.write(num.toPrecision(2) + "<br/>"); //5.123
document.write(num.valueOf() + "<br/>");  //5.123
document.write(num.toExponential(1));   //5.1e+0


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:JavaScript eventsNext article:JavaScript events