This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### float
Examples |
    float a;           // Declare variable 'a' of type float
    a = 1.5387;        // Assign 'a' the value 1.5387
    float b = -2.984;  // Declare variable 'b' and assign it the value -2.984
    float c = a + b;   // Declare variable 'c' and assign it the sum of 'a' and 'b'
    float f = 0;
    for (int i = 0 ; i < 100000; i++) {
      f = f + 0.0001;  // Bad idea! See below.
    }

    for (int i = 0; i < 100000; i++) {
      // The variable 'f' will work better here, less affected by rounding
      float f = i / 1000.0;  // Count by thousandths
    }
Description | Data type for floating-point numbers, a number that has a decimal point. Floats are not precise, so avoid adding small values (such as 0.0001) may not always increment because of rounding error. If you want to increment a value in small intervals, use an int, and divide by a float value before using it. (See above example.) Floating-point numbers can be as large as 3.40282347E+38 and as low as -3.40282347E+38. They are stored as 32 bits (4 bytes) of information. The float data type is inherited from Java, and you can read more about the technical details here or here. Processing supports the 'double' datatype from Java as well, however it is not documented because none of the Processing functions use double values, which are overkill for nearly all work created in Processing and use more memory. We do not plan to support doubles, as it would require increasing the number of API functions significantly.
Syntax |
    float var
    float var = value
Parameters |
var | variable name referencing the float
value | any floating-point value
Related | int

Updated on May 19, 2014 05:30:05pm PDT