HTML and CSS Reference
In-Depth Information
Figure 11-28
numeric functions and methods
Function or Method
Description
isFinite( value )
Returns a Boolean value indicating whether value is finite and a
legal number
isNaN( value )
Returns a Boolean value, which has the value true if value is not
a number
parseFloat( string )
Extracts the first numeric value from a text string, string
parseInt( string )
Extracts the first integer value from a text string, string
value .
toExponential( n )
Returns a text string displaying value in exponential notation with n dig-
its to the right of the decimal point
value .toFixed( n ) Returns a text string displaying value to n decimal places
value .toPrecision( n ) Returns a text string displaying value to n significant digits either to the
left or to the right of the decimal point
Because the countdown clock is not performing any calculations on values within the
Web form, you don't need to use the parseInt() , parseFloat() , or eval() functions
in your code. However, you will have an opportunity to practice using these functions in
the Case Problems at the end of the tutorial.
Using Numeric Methods and Functions
• To display a numeric value to a set number of digits, use the function
value .toFixed( n )
where value is the numeric value and n is the number of digits to the right of the
decimal place to be displayed. The toFixed() method converts the numeric value to
a text string.
• To extract an integer from the beginning of a text string, use
parseInt( string )
where string is a text string that starts with an integer value.
• To extract a numeric value from the beginning of a text string, use
parseFloat( string )
where string is a text string that starts with a numeric value.
• To test whether a value represents a number, use
isNaN( value )
where value can be a text string, a numeric value, or another data type. The isNaN()
function returns the Boolean value true if value is not a number or false if it is.
• To convert a text string to a numeric value, use
eval( string )
where string is either a text string of a numeric value or a text string of a numeric
expression that returns a numeric value.
Search WWH ::




Custom Search