While programming, you might run into a situation where you want to convert a variable of the integer type to a float, or a float to a String. In this recipe, we'll take a look at some handy functions you can use to do this.
The code for this example is fairly simple. The functions to convert the data are used within the println()
function, so that we can directly print the value they return to the console. The following is the full code for the example:
int number1 = 65; float number2 = 7.537; void setup() { noLoop(); } void draw() { // convert int to float println( float( number1 ) ); // convert float to int println( int( number2 ) ); // convert a number to a binary string println( binary( number1 ) ); // convert a binary string to a number println( unbinary( "0010110011100110" ) ); // convert numbers or a string to a boolean println( boolean( 1 ) ); println( boolean( number1 ) ); println( boolean( 0 ) ); println...