Datatype Conversion.

Datatype Conversion.

It is sometimes beneficial to convert a value from one type of data to another. Each of the conversion functions converts its parameter to an equivalent representation within its datatype. The conversion functions include int(), float(), char(), byte(), and others.


size(640, 360);
background(0);
noStroke();

textFont(createFont("SourceCodePro-Regular.ttf",24));

char c;    // Chars are used for storing alphanumeric symbols
float f;   // Floats are decimal numbers
int i;     // Integers are values between 2,147,483,647 and -2147483648
byte b;    // Bytes are values between -128 and 128

c = 'A';
f = float(c);      // Sets f = 65.0
i = int(f * 1.4);  // Sets i to 91
b = byte(c / 2);   // Sets b to 32

//println(f);
//println(i);
//println(b);

text("The value of variable c is " + c, 50, 100);
text("The value of variable f is " + f, 50, 150);
text("The value of variable i is " + i, 50, 200);
text("The value of variable b is " + b, 50, 250);

Functions Used

size()

Defines the dimension of the display window width and height in units of pixels

Learn More
println()

The println() function writes to the console area, the black rectangle at the bottom of the Processing environment

Learn More
int

Datatype for integers, numbers without a decimal point

Learn More
text()

Draws text to the screen

Learn More
textFont()

Sets the current font that will be drawn with the text() function

Learn More
byte

Datatype for bytes, 8 bits of information storing numerical values from 127 to -128

Learn More
noStroke()

Disables drawing the stroke (outline)

Learn More
float

Data type for floating-point numbers, e

Learn More
background()

The background() function sets the color used for the background of the Processing window

Learn More