float point value range

Description

Not all numbers in the world can be represented in Javascript. The value range are identified by four special values in Javascript.

  • Number.MIN_VALUE represents the smallest value in JavaScript.
  • Number.MAX_VALUE stores the largest number.
  • Number.NEGATIVE_INFINITY is the negative infinity.
  • Number.POSITIVE_INFINITY is the positive infinity.

Example


var result = Number.MAX_VALUE + Number.MAX_VALUE; 
console.log(result); //from   w ww.  j  a v  a2s  . c  o m

console.log(Number.MAX_VALUE); 
console.log(Number.MIN_VALUE); 
console.log(Number.NEGATIVE_INFINITY); 
console.log(Number.POSITIVE_INFINITY); 


if((Math.sqrt(-2)) != Number.NEGATIVE_INFINITY_){
    console.log("This is not equal to NEGATIVE_INFINITY");
}
else{
    console.log("This is equal to NEGATIVE_INFINITY");
}

if((Math.exp(999)) <= Number.POSITIVE_INFINITY_){
   console.log("This is less than positive infinity");
}
else{
   console.log("This is greater than POSITIVE_INFINITY");
}

if((99999*99999) <= Number.MAX_VALUE){
   console.log("greater than the maximum value");
}
if((0.0000000001) >= Number.MIN_VALUE){
   console.log("The number is not the minimum value");
}

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions