?Explain briefly about converting between numbers and text.
What will be an ideal response?
?Sometimes, it is necessary to convert a number to a text string and vice versa. One way to convert a number to a text string is by using the + operator to add a text string to a number. For example, the following code uses the + operator to concatenatea numeric value with an empty text string. The result is a text string containing thecharacters 123.testNumber = 123; // numeric valuetestString = testNumber + ""; // text stringTo convert a text string to a number, one can apply an arithmetic operator (otherthan the + operator) to the text string. The following code takes the text string 123 andmultiplies it by 1. JavaScript converts the text string "123" to the numeric value 123.testString = "123"; // text stringtestNumber = testString*1; // numeric valueAnother way of converting a text string to a numeric value is to use the followingparseInt()function, which extracts the leading integer value from a text stringparseInt(text)wheretextis the text string or variable from which the user wants to extract the leadinginteger value. TheparseInt()function returns the integer value from the text string,discarding any non-integer characters. If a text string does not begin with an integer,the function returns the valueNaN, indicating that the text string contains no accessiblenumber. The following are some sample values returned by theparseInt() method:parseInt("120 lbs"); // returns 120parseInt("120.88 lbs"); // returns 120parseInt("weight equals 120 lbs"); // returns NaN
You might also like to view...
You can insert captions or titles for photos in a PowerPoint photo album
Indicate whether the statement is true or false
The Find and Replace dialog box can be opened from the Navigation pane by first clicking the:
A) Headings command. B) Pages command. C) Results command. D) "Search for more things" arrow.