本参考资料用于Processing 3.0+。 如果你使用的是前一版本,请在使用软件帮助菜单内的参考资料。. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.



float a;

 //Declare variable 'a' of typefloat
a = 1.5387;

  // Assign 'a' the value 1.5387float b = -2.984;

 // Declare variable 'b' and assign it the value -2.984float c = a + b;

// Declare variable 'c' and assign it the sum of 'a' and 'b' 

float f1 = 0.0;

for (int i = 0 ;

i < 100000;

f1 = f1 + 0.0001;

 // Bad idea! See below.

float f2 = 0.0;

for (int i = 0;

i < 100000;

// The variable 'f2' will work better here, less affected by rounding   f2 = i / 1000.0;

 // Count by thousandths

描述 Data type forfloating-point numbers, e.g. numbers that have a decimal point.

Floats are not precise, so adding small values (such as 0.0001) may not always increment precisely due to rounding errors. If you want to increment a value in small intervals, use an int, and divide by a float value before using it. (See the second example above.)

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;

you can read more about the technical details here and here.

Processing supports the double datatype from Java as well. However, none of the Processing functions use double values, which use more memory and are typically overkill for most work created in Processing. We do not plan to add support for double values, as doing so would require increasing the number of API functions significantly.

float varfloat var = value 
var variable name referencing thefloat
value anyfloating-point value
相关 int

Updated on October 2, 2018 05:02:16pm EDT