JS - Number Methods
5 flashcards · Programming Languages · by zeckdude
What is the number method to determine if a number is an integer (whole number)? Provide example using the supplied code: num = 5
Number.isInteger(number) // returns true
What is the number method to get a floating point number from the beginning of a string? Provide example using the supplied code: str = '40.5 papers'
Number.parseFloat(str) // returns 40.5
What is the number method to get an integer (whole number) from the beginning of a string? Provide example using the supplied code: str = '40.5 papers'
Number.parseInt(str) // returns 40
What is the number method to format a number to use a specified amount of characters after the decimal point? Answer the following question: Does this method round the number up or down at the end of numbers after the decimal point? Provide example using the supplied code: num = 123.4567 Format the number to use two characters after the decimal point
num.toFixed(2) // returns 124.46
What is the number method to convert a number to a string? Provide example using the supplied code: num = 123
num.toString(num) // returns "123"