Name

float()

Description

Converts an int or String to its floating point representation. An int is easily converted to a float, but the contents of a String must resemble a number, or NaN (not a number) will be returned. For example, float("1234.56") evaluates to 1234.56, but float("giraffe") will return NaN.

When an array of int or String values is passed in, then a floating point array of the same length is returned.

Examples

  • int i = 65;
    float f = float(i);
    println(i + " : " + f);  // Prints "65 : 65.0"