Converting text list to numbers list

I wrote following script to be able convert text list to numbers list:


my makeNumericList:{"10.5", "3.14", "5", "1"}

on makeNumericList:stringsList
	set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
	set numericList to (run script ("{" & stringsList & "}"))
	set AppleScript's text item delimiters to ATID
	return numericList
end makeNumericList:

It is very fast and works correctly when current decimal separator of user is “.”, but returns wrong list when separator is other.

Any suggestion to make it to work with any current decimal separator for numbers, without using repeat loop?

This might do it if the strings don’t contain thousands separators:


my makeNumericList:{"10.5", "3,14", "123 7", "5", "1"}

on makeNumericList:stringsList
	set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "?"}
	set {numberText, AppleScript's text item delimiters} to {stringsList as text, {".", ",", space}}
	set {stringsList, AppleScript's text item delimiters} to {numberText's text items, middle character of (0.0 as text)}
	set {numberText, AppleScript's text item delimiters} to {stringsList as text, "?"}
	set {stringsList, AppleScript's text item delimiters} to {numberText's text items, ","}
	set {numericList, AppleScript's text item delimiters} to {(run script ("{" & stringsList & "}")), ATID}
	return numericList
end makeNumericList:

@Nigel Garvey,

I confirm that it works exactly as I would like. Thousand separators don’t really interest me at the moment. Thanks a lot.

Here’s my version

my makeNumericList:{"10,5", "3,14", "5", "1"}

on makeNumericList:stringsList
	set {ATID, text item delimiters} to {text item delimiters, "\" as number,\""}
	set numericList to (run script ("{\"" & stringsList & "\" as number}"))
	set text item delimiters to ATID
	return numericList
end makeNumericList:


Thanks, but

this handler throws error for the users whose current decimal separator is “.” instead of “,”
It should be refined somewhat.

I didn’t see that as an issue, since why would I have a list with the other decimal seperator in my list in the first place.
That is why my list contains commas to test the systems with a comma seperator.

But I see your point

The numeric text list is returned with different decimal separators by different shell commands or from the webpages. The handler should take this fact into the attention.