float

Float built-in type.

Description

float built-in type is a 64-bit double-precision floating-point number, equivalent to double in C++. This type has 14 reliable decimal digits of precision. The float type can be stored in Variant, which is the generic type used by the engine. The maximum value of float is approximately 1.79769e308, and the minimum is approximately -1.79769e308. float in C++, which have 6 reliable decimal digits of precision. For data structures such as Vector2 and Vector3, Godot uses 32-bit floating-point numbers. float type is not guaranteed to be exact or deterministic, and will often result in small errors. You should usually use the @GDScript.is_equal_approx and @GDScript.is_zero_approx methods instead of == to compare float values for equality.

Tutorials

  • Wikipedia: Double-precision floating-point format
  • Wikipedia: Single-precision floating-point format

    Methods

    Method Descriptions

  • float float ( bool from ) bool value to a floating-point value, float(true) will be equal to 1.0 and float(false) will be equal to 0.0.

  • float float ( int from ) int value to a floating-point value, float(1) will be equal to 1.0.

  • float float ( String from ) String value to a floating-point value. This method accepts float value strings like "1.23" and exponential notation strings for its parameter so calling float("1e3") will return 1000.0 and calling float("1e-3") will return 0.001. Calling this method with an invalid float string will return 0. This method stops parsing at the first invalid character and will return the parsed result so far, so calling float("1a3") will return 1 while calling float("1e3a2") will return 1000.0.