首页 > 未分类 > float浮点数
2017
07-15

float浮点数

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浮点数 - 第1张  | Processing编程艺术

float f1 = 0.0;

for (int i = 0 ; i < 100000; i++) {

f1 = f1 + 0.0001; // Bad idea! See below.

}

println(f1);

 

float f2 = 0.0;

for (int i = 0; i < 100000; i++) {

// The variable ‘f2’ will work better here, less affected by rounding

f2 = i / 1000.0; // Count by thousandths

}

println(f2);

Description

描述

Data type for floating-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.

floating-point 数字的数据类型, 例如具有小数点的数字。

 

浮点不精确, 因此添加小值 ( 0.0001) 可能不会因为舍入错误而精确递增。如果要以较小的间隔递增值, 请使用 int, 然后在使用浮点值之前将其除以。(请参见上面的第二个示例。

 

浮点数字可以是3.40282347E+38 和低至 3.40282347E + 38 的大小。它们存储为32 (4 字节) 的信息。浮点数据类型是从 java 继承的;您可以在这里和这里阅读更多有关技术细节的信息。

 

处理也支持来自 java 的双重数据类型。但是, 任何处理函数都不使用双精度值, 这会占用更多的内存, 并且对于在处理过程中创建的大多数工作来说通常是矫枉过正。我们不打算增加对双精度值的支持, 因为这样做需要显著增加 api 函数的数量。

Syntax

语法

float var

float var = value

Parameters

参数

var

variable name referencing the float

value

any floating-point value

Related相关

int
double



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。