Can not convert \”22.5\” to number

While writing a script to get some information from top of the command line into applescript
and compare the numbers I stumbled upon a problem.
 
While top returns 22.5 applescript on my mac sees a number as 22,5.
 
The mac I use has german as locale, looks like the locale of the command line isn’t the same
and uses us notation.
 
So I created a short snippet to convert a string from 22.5 to 22,5 which can than be converted
to a number in applescript.
 
  on dotStringNumber2commaStringNumber(stringNumber)

       set resultNumber to ""
       set char_list to every character of stringNumber
       set char_list_length to count char_list
       repeat with x from char_list_length to 1 by -1
                 set current to ( item (char_list_length - x + 1) of char_list) as string
                 if current = "." then set current to ","
                 set resultNumber to resultNumber & current
       end repeat
       return resultNumber


 end dotStringNumber2commaStringNumber
 
I know this isn’t the best solution but I haven’t found a simpler one, perhapsmsomebody else knows.
 
 
 
Advertisements

One thought on “Can not convert \”22.5\” to number

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s