IntToFloat

From NWN Lexicon
Revision as of 07:13, 24 June 2019 by Shadguy (talk | contribs) (Spelling fix(es))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search



IntToFloat(int)

This function converts an int to a float of the same value.

float IntToFloat(
    int nInteger
);

Parameters

nInteger

The integer to convert into a float.


Description

This function coverts an integer to a float of the same value, so that converting 123 to a float would yield 123.00.



Remarks

Since the internal size of a float (3.4028183957828877e+38) is larger than an integer (2147483647) there will be no precision loss in this conversion.


Known Bugs

Testing revealed that the least significant digit was being approximated in numbers approaching the Integer maximum (2147483647) and Minimum (-2147483647).

The results are as follows:
2147483647 = 2147483648.00
2147482647 = 2147482624.00
2147473647 = 2147473664.00
2147383647 = 2147383680.00
2146483647 = 2146483584.00
2137483647 = 2137483648.00
2047483647 = 2047483648.00
1147483647 = 1147483648.00
147483647 = 147483648.00
47483647 = 47483648.00

Note that since this occurs only with very large numbers being converted (Ten Million and Beyond) this should not be an issue with most scripts.


Version

1.30

Example

// Convert the age of the PC who uses this object into a float value.
// This is then the duration of a regeneration effect applied to the PC
// Go oldies!
void main()
{
    // Declare who is clicking on us
    object oClicker = GetClickingObject();

    // Get their age
    int nAge = GetAge(oClicker);

    // Convert to float, which can be used as some form of time
    float fAge = IntToFloat(nAge);

    // Heals 1HP each 1 second, for an amount of seconds equal to
    // the persons age
    effect eRegen = EffectRegenerate(5, 1.0);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eRegen, oClicker, fAge);
}

See Also

functions: 

IntToString



 author: Charles Feduke, editor: Jasperre, additional contributor(s): Lilac Soul