javaScript Number object

javascript numbers can be written with, or without decimals.

all javascript numbers are 64-bit floating-point numbers.

number object

the number object is an object wrapper for primitive numeric values.

number objects are created with new number().

syntax:

        var   numobj  =  new   number(value ) ;
  • numobj is required.the variable name to which the number object is assigned.
  • value required.the numeric value.
examples:

                        var   first  =     new   number(1212.1212);  
         
                        var   second =  new   number(123e-5);          //scientific notation  

numeric constants represent in octal and hexadecimal format.octal if they are preceded by a zero, and as hexadecimal if they are preceded by a '0x'

                        var   octal_value = 02323;
                      
                        var   hex_value   = 0x2323;

JavaScript number object properties

propertydescription
max_valuethe largest positive representation number
min_valuethe smallest positive representation number
positive_infinityrepresents positive infinity(returned on overflow)
negative_infinityrepresents negative infinity(returned on overflow)
nanrepresents a 'not a number' value
prototypeallows you to add properties and methods to an object
 <script>
 
            var   max_value     =   number.max_value ;
            
            var   min_value      =   number.min_value ;
            
            var   positive_infi   =   number.positive_infinity ;
            
            var   negative_infi  =   number.negative_infinity ;

            var   nan              =   number.nan;
            
                   document.write("the max_value is______"+ max_value);
                  
                   document.write("the min_value is______"+ min_value);
                  
                   document.write("the positive_infinity______"+ positive_infi);
                  
                   document.write("the negative_infinity______"+ negative_infi);
                  
                   document.write("the nan value_______"+ nan);
                  
    </script>              

JavaScript number object methods

methoddescription
tostring()converts a number object to a string
valueof()returns the primitive value of a number object
toexponential(x)returns a string that contains a number represented in exponential notation.
tofixed(x)returns a string that represents a number in fixed-point notation.
toprecision(x)formats a number to x length
    var         x  =  new   number(2323.54673) ;
                
    var        string =  x.tostring();
                
    var        value  =  (34.34).valueof();
                
    document.write("<br/>"+"the x value ___"+ x);
                
    document.write("<br/>"+"the type of string variable____ "+typeof (string));
                
    document.write("<br/>"+"the value variable____"+ value);
     var     x  =  new  number(234.5454);
     
document.write("the x change into exponential value___"+ x.toexponential(3));

document.write('<br/>'+"fix the digits___ "+ x.tofixed(2));

document.write('<br/>'+"fix the digits___"+  x.tofixed(8));

document.write('<br/>'+"format the x value___"+ x.toprecision(3));

document.write('<br/>'+"format the x precision"+ x.toprecision(7));