Difference between revisions of "SHIP:Sail:itof"

From Serious Documentation
Jump to: navigation, search
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
{{SailFuncTableStart|}}<onlyinclude>
 
{{SailFuncTableStart|}}<onlyinclude>
|{{SailFunc|itof}}||{{DataType|Integer}}||1||Explicitly casts an {{DataType|Integer}} to a {{DataType|Float}} {{v5}}</onlyinclude>
+
|{{SailFunc|itof}}||{{DataType|Integer}}||style="text-align:center;"|v5.0||Explicitly casts an {{DataType|Integer}} to a {{DataType|Float}} {{v5}}</onlyinclude>
 
|}
 
|}
This function was introduced in [[SHIP_Version_5|SHIP Version 5.0]].
 
 
== See Also: ==
 
== See Also: ==
 
*[[SHIP:Sail|Sail Home]]
 
*[[SHIP:Sail|Sail Home]]

Revision as of 05:25, 14 July 2014

Function Returns Introduced Description
itof Integer v5.0 Explicitly casts an Integer to a Float Badge SHIPv5.gif

See Also:

Prototype

Float itof(Integer n);

Parameters/Return Value

Parameter Data Type Description
n Integer the number to cast
Return Float the floating point version of the supplied number

Detailed Description

The itof() function explicitly casts the supplied Float to an Integer. You may want to use this in mathematical expressions around items so that the expression evaluation is moved into the floating point domain. For example:

intValue = 5/4*10;

will return 10 since the whole expression is evaluated at run-time in the Integer domain, and 5/4 will be evaluated using integer math resulting in 1. However,

intValue = 5/itof(4)*10;

will return 11 since the 5/4 will be evaluated using floating point math. Obviously, this is equivalent to:

intValue = 5/4.0f*10;

However,this methodology becomes more useful when a function that returns a Integer is used:

intValue = 5/itof(strlen(s))*10;

Examples

Example Result Notes
itof(-5); -5.0
itof(5); 5.0