Up to date

This page is up to date for Godot `4.2`. If you still find outdated information, please open an issue.

# float¶

## 描述¶

float 内置类型是 64 位双精度浮点数，相当于 C++ 中的 `double`。这个类型有 14 个可靠的十进制小数位精度。float 的最大值约为 `1.79769e308`，最小值约为 `-1.79769e308`

## 构造函数¶

 float float ( ) float float ( float from ) float float ( String from ) float float ( bool from ) float float ( int from )

## 操作符¶

 bool operator != ( float right ) bool operator != ( int right ) Color operator * ( Color right ) Quaternion operator * ( Quaternion right ) Vector2 operator * ( Vector2 right ) Vector2 operator * ( Vector2i right ) Vector3 operator * ( Vector3 right ) Vector3 operator * ( Vector3i right ) Vector4 operator * ( Vector4 right ) Vector4 operator * ( Vector4i right ) float operator * ( float right ) float operator * ( int right ) float operator ** ( float right ) float operator ** ( int right ) float operator + ( float right ) float operator + ( int right ) float operator - ( float right ) float operator - ( int right ) float operator / ( float right ) float operator / ( int right ) bool operator < ( float right ) bool operator < ( int right ) bool operator <= ( float right ) bool operator <= ( int right ) bool operator == ( float right ) bool operator == ( int right ) bool operator > ( float right ) bool operator > ( int right ) bool operator >= ( float right ) bool operator >= ( int right ) float float

## 构造函数说明¶

float float ( )

float float ( float from )

float float ( String from )

String 转换为 float，遵循与 String.to_float 相同的规则。

float float ( bool from )

bool 值转换为浮点值，`float(true)` 将等于 1.0，`float(false)` 将等于 0.0。

float float ( int from )

int 值转换为浮点值，`float(1)` 将等于 `1.0`

## 操作符说明¶

bool operator != ( float right )

bool operator != ( int right )

Color operator * ( Color right )

```print(1.5 * Color(0.5, 0.5, 0.5)) # 输出“(0.75, 0.75, 0.75, 1.5)”
```

Quaternion operator * ( Quaternion right )

Vector2 operator * ( Vector2 right )

```print(2.5 * Vector2(1, 3)) # 输出 "(2.5, 7.5)"
```

Vector2 operator * ( Vector2i right )

```print(0.9 * Vector2i(10, 15)) # 输出 "(9, 13.5)"
```

Vector3 operator * ( Vector3 right )

Vector3 operator * ( Vector3i right )

```print(0.9 * Vector3i(10, 15, 20)) # 输出 "(9, 13.5, 18)"
```

Vector4 operator * ( Vector4 right )

Vector4 operator * ( Vector4i right )

```print(0.9 * Vector4i(10, 15, 20, -10))# 输出 "(9, 13.5, 18, -9)"
```

float operator * ( float right )

float operator * ( int right )

floatint 相乘。结果是 float

float operator ** ( float right )

float 提升到 float 次幂。

```print(39.0625**0.25) # 2.5
```

float operator ** ( int right )

float 提升到 int 次幂。结果为 float

```print(0.9**3) # 0.729
```

float operator + ( float right )

float operator + ( int right )

float 加上 int。结果为 float

float operator - ( float right )

float operator - ( int right )

float 减去 int。结果为 float

float operator / ( float right )

float operator / ( int right )

float 除以 int。结果是 float

bool operator < ( float right )

bool operator < ( int right )

bool operator <= ( float right )

bool operator <= ( int right )

bool operator == ( float right )

bool operator == ( int right )

bool operator > ( float right )

bool operator > ( int right )

bool operator >= ( float right )

bool operator >= ( int right )

float operator unary+ ( )

float operator unary- ( )