The int() function in p5.js is used to convert the given boolean, integer, and float value into its integer representation.
Parameters: This function accepts three types of the parameter which are listed below:
- n: It stores the value which needs to converts into integer. The possible value of n is string, boolean, or number.
- radix: It stores the radix part to which the number is converted.
- ns: It stores different types of elements into the array.
Return Value: It returns the converted integer representation.
Below programs illustrate the int() function in p5.js:
Example 1: This example uses int() function to convert input value into its integer value.
Example 2: This example uses int() function to convert input value into its integer value.
Note: From the above program, if the value of the parameter is number then it returns the output as integer representation, for false it returns 0 and for true it returns 1 and for string values, it returns NaN i.e, not a number.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.