Here's a few more:
isNumber
function isNumber(%flag)
{
if(%flag $= "")
return 0;
%check = "-.0123456789";
%lastPos = -1;
for(%i=0; %i < strLen(%flag); %i++)
{
%char = getSubStr(%flag,%i,1);
%pos = strPos(%check,%char);
if(%pos < 0)
return 0;
if(%pos == 0)
{
if(%neg)
return 0;
if(%lastPos < 2 && %lastPos >= 0)
return 0;
%neg = 1;
}
if(%pos == 1)
{
if(%dec)
return 0;
if(%lastPos < 2 && %lastPos >= 0)
return 0;
%dec = 1;
}
%lastPos = %pos;
}
return 1;
}
Any valid number (152, -5.7, 64.90, -93) will return true.
stripTrailingZeros
function stripTrailingZeros(%flag)
{
if(!isNumber(%flag))
return %flag;
%pos = -1;
for(%i=0; %i < strLen(%flag); %i++)
{
%char = getSubStr(%flag,%i,1);
if(%char $= ".")
{
%dec = 1;
%pos = %i;
%zero = 1;
continue;
}
if(%char $= "0" && %dec)
{
if(!%zero)
%pos = %i;
%zero = 1;
}
else
{
%zero = 0;
%pos = -1;
}
}
if(%pos > 0)
%flag = getSubStr(%flag,0,%pos);
return %flag;
}
Removes excess 0's from the end of a decimal. (5.679000 => 5.679)