Download

Limit decimals in float conversions

When converting a float to a string always gives 4 decimals. It’s easy to limit with a function like this:

function string FloatRound(float F, byte MaxD)
{
local string S;
local int P;
if (F == int(F)) { return string(Int(F)); }
S = string(F);
P = InStr(S,".");
return left(S,P)$"."$mid(S,P+1,MaxD);
}
that returns an integer if the float has no decimals, or a float with (MaxD) decimals.

But there are some native function to do the same (and more quickly)? I want it to serialize float values.