We can use sprintf from msvcrt.dll.
But here is a function to support decimal-point alignment in a column, taking care of left and right spacing.
function dp_str(string num="", int wid=20, dpp=10) as string
===========================================================
'num number string
'wid column width
'dpp decimal point position in column
'
string buf 'column buffer
int ln 'length of num
int dp 'offset of num decimal point
'
buf=space(wid) ' column string
ln=len(num)
dp=instr(num,".")
if dp=0 'integers
dp=ln+1
endif
'
int n=dpp-dp 'left spaces
'check if too long
if n<0 then n=0 'remove left space
if ln>wid
mid buf,1,"!!"+num 'error
else
mid(buf,1+n,num) 'copy number into position
endif
return buf
end function
'TESTS
uses console
print dp_str(pi(),30) "|" cr
print dp_str(pi(),30,4) "|" cr
print dp_str(str(pi(),5)) "|" cr
print dp_str(12345678) "|" cr
print dp_str(123) "|" cr
print dp_str(-123) "|" cr
print dp_str(-123.45) "|" cr
wait