API Reference › Builtin functions › float
function

float

float(x) -> float / double(x) -> double

Converts an int, long, fixed, float or double to a float (or, with double(x), to a double). It is the one conversion that crosses from fixed-point to floating point: float(fixed(1)) / 4.0 is 0.25. A decimal literal converts exactly, so float(0.1) is the nearest float to 0.1, not the nearest Q16.16 value.

Parameters

xthe number to convert

Example

program Convert {
  entry {
    let half = fixed(1) / 2
    print(float(half) * 3.0)           # 1.5
    print(double(7) / 2)               # 3.5
  }
}
← All symbols