To float

From Kolmafia
Jump to navigation Jump to search

Function Syntax

float to_float(boolean convert )

float to_float(int convert )

float to_float(string convert )

  • convert is the boolean, int, or string to convert

This function looks for the best float match to the specified input, which varies by datatype. For int types, this function merely tacks ".0" to the end. For booleans, a transparent conversion as per to_int() is performed first, and then converted to a float. All other data types do not work.

Code Samples

Following example shows basic to_float operations.

int first = 25;
print("Int "+first+" gives "+to_float(first), "green");
foreach it in $booleans[]
   print("Boolean "+it+" gives "+to_float(it), "blue");

It gives the following output.

Int 25 gives 25.0
Boolean true gives 1.0
Boolean false gives 0.0