Formatting a number with two or more decimal points
James Hale
james at thehales.id.au
Wed Nov 11 08:22:29 EST 2015
You could just use the replace function.
function newnum pnum
put offset(".",pnum,3) into trem
if trem = 0 then --only a single decimal
return pnum
else
--we have more than on decimal, remove good number for later
put char 1 to trem+2 of pnum into newnum
delete char 1 to trem+2 of pnum
--fix remaining numbers
replace "." with " 0." in pnum
--return the lot
return newnum&pnum
end if
end newnum
This assumes the numbers to unpack are less than 100 (i.e. 99.99 is the largest).
If not, you would need to adjust the initial conditional to work out if there was a compaction.
James
More information about the use-livecode
mailing list