Re: Formatting a number with two or more decimal points
A number with more than one period... is not a number. An IP address is not a number. It's a period delimited list of decimal values ranging from 0 to 255. It may help to think of them as such. Bob S ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Formatting a number with two or more decimal points
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 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 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Formatting a number with two or more decimal points
Hi All, on Wed Nov 11, Matt Maier wrote: > This works with the two cases you described. > I've heard that "repeat while" isn't the fastest option, > but it sounded like 6 repeats would be an extreme > case, so it probably doesn't matter... on Wed Nov 11, James Hale wrote: > You could just use the replace function. > [snip] > 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. Great! Many Thanks to Matt and James for posting this code :D I found an example of 13 numbers in a single word within a svg file. I have already included Matt's handler in the stack SVGL_2015_rev01 posted within this thread in the forums: http://forums.livecode.com/viewtopic.php?f=10=25612=134343#p134309 Later today, I will test James handler. After completed all revisions, I will include links to your messages in the mail list or forum to acknowledge your contributions. Many Thanks for your help to update this stack! You could download the Original SVGL stack from: http://livecodeshare.runrev.com/stack/112/SVGL Alejandro ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Formatting a number with two or more decimal points
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 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Formatting a number with two or more decimal points
This works with the two cases you described. I've heard that "repeat while" isn't the fastest option, but it sounded like 6 repeats would be an extreme case, so it probably doesn't matter. on testingTesting -- 10.26.12.47.38.52.71 -- 10.26 0.12 0.47 0.38 0.52 0.71 -- put "80.26.12" into tBlerg -- put "10.26.12.47.38.52.71" into tBlerg put "10.26" into tBlerg put convertWordToNumbers(tBlerg) into tBlergBlerg end testingTesting function convertWordToNumbers pWordN put pWordN into tWord split tWord by "." if the number of lines of the keys of tWord > 2 then put tWord[1] & "." & tWord[2] into tAll put 3 into tCounter repeat while tCounter <= the number of lines of the keys of tWord put " 0."& tWord[tCounter] after tAll put tCounter + 1 into tCounter end repeat return tAll end if return pWordN end convertWordToNumbers On Tue, Nov 10, 2015 at 5:07 PM, Alejandro Tejadawrote: > 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 > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode