Code: Select all
void traceFloat(float n, byte d) {
string integer = intToStr(n);
string dust = subStr(intToStr(n * pow(10, d)), length(integer), d);
trace(integer + "." + dust);
}
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
<OnLoaded>
<ZLibrary>
<Source>
<![CDATA[void traceFloat(float n, byte d) {
if (d>8) d = 8;
int integer = n;
string str_integer = intToStr(integer);
float decimals = n - integer;
int dec2int = abs(decimals * pow(10, d));
string str_decimals = intToStr(dec2int);
trace(str_integer + "." + str_decimals);
}]]>
</Source>
</ZLibrary>
<ZExpression>
<Expression>
<![CDATA[trace("");
traceFloat(1000.123456789, 5);
traceFloat(100.123456789, 5);
traceFloat(0.123456789, 5);
trace("");]]>
</Expression>
</ZExpression>
</OnLoaded>
</ZApplication>
I guess it is some kind of limitation with int or float size, but I don't understand why...?
Also, there may be a better way to do that