Difference between revisions of "To float"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
(Created page with '{{ #vardefine:name|to_float}}{{ #vardefine:return_type|float}}{{ FunctionPage| name={{#var:name}}| function_category=Datatype Conversions| function1={{Function| name={{#var:nam…')
 
imported>Eliteofdelete
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Datatype Conversions|
 
  
 
function1={{Function|
 
function1={{Function|
Line 12: Line 11:
 
return_type={{#var:return_type}}|
 
return_type={{#var:return_type}}|
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
parameter1= '''any''' {{pspan|anything}}|
+
parameter1={{Param|boolean|convert}}|
p1desc={{Pspan|anything}} is any data type that KoLmafia uses|
 
 
}}|
 
}}|
  
function_description=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 all others, a transparent conversion as per [[to_int|to_int()]] is performed first, and then converted to a float.|
+
function2={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|int|convert}}|
 +
}}|
  
needscode=yes|
+
function3={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|string|convert}}|
 +
p1desc={{Pspan|convert}} is the boolean, int, or string to convert|
 +
}}|
 +
 
 +
function_description=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|to_int()]] is performed first, and then converted to a float. All other data types do not work.|
 +
 
 +
code1={{CodeSample|
 +
title=Code Samples|
 +
description=Following example shows basic to_float operations.||
 +
code=
 +
<syntaxhighlight>
 +
int first = 25;
 +
print("Int "+first+" gives "+to_float(first), "green");
 +
foreach it in $booleans[]
 +
  print("Boolean "+it+" gives "+to_float(it), "blue");
 +
 
 +
</syntaxhighlight>|
 +
moreinfo=
 +
It gives the following output.
 +
<pre>
 +
Int 25 gives 25.0
 +
Boolean true gives 1.0
 +
Boolean false gives 0.0
 +
</pre>
 +
}}|
  
 
}}
 
}}
 +
 +
[[Category:Datatype Conversions]]

Latest revision as of 14:46, 26 January 2015

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