Formatting a number with two or more decimal points

Alejandro Tejada capellan2000 at gmail.com
Tue Nov 10 20:07:56 EST 2015


Hi All,

Recently, while updating Ian's SVGL
to import some SVG archives that
you could download from OpenClipart.org
I found an error processing this number:
80.26.12

This looks like a number with two decimal points
but it's a shorthand for two numbers that some
SVG editors use to save space by replacing two numbers
like 80.26 0.12 with a single word like this: 80.26.12
Notice that two characters: " 0" (a space and
number zero) are missing.

Quickly, I scripted a workaround like this:

Function ConvertWordtoNumbers pWordN

put pWordN into tWordNumber -- pWordN contains "80.26.12"

if "." is in tWordNumber
then

replace "." with cr in tWordNumber
if the number of lines of tWordNumber = 3
then
return line 1 of tWordNumber & "." & line 2 of tWordNumber && "0." & line 3
of tWordNumber
else return pWordN -- unchanged word or unchanged number
end if

else
return pWordN
end if

end ConvertWordtoNumbers

My question is:
How could you rewrite this code
to make it more elegant, faster,
efficient and cover an extreme
case like this:
10.26.12.47.38.52.71
(6 numbers in a single word)
10.26 0.12 0.47 0.38 0.52 0.71

Autotracing applications could produce
curves as unusual as these.

Thanks in advance!

Al



More information about the use-livecode mailing list