More with numbers
More with numbers
- Subject: More with numbers
- From: Stephen Swift <email@hidden>
- Date: Tue, 09 Jul 2002 16:09:19 -0400
Now it may be just the AppleScript version I'm working with (1.3.7), but I'm
running into something odd in AppleScript...
89741321798462498984765 as real
--> returns a syntax error.
8.974132179846251e+22 + 1.0
--> returns a syntax error.
However, I have gotten AppleScript to convert it to a real. Take a look at
this script:
--I put in the equation, "89741321798462498984765 + 1"
set dlg to display dialog "Type your equation. Make sure to put a space
between each number." default answer ""
set finalText to text returned of dlg
set eq_list to {}
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set ftxtchars to text items of finalText
set AppleScript's text item delimiters to OldDelims
--{"89741321798462498984765","+","1"}
repeat with i from 1 to (count ftxtchars)
if item i of ftxtchars is "+" then
set next_val to "+"
else
set next_val to item i of ftxtchars as real
--"89741321798462498984765" as real
--?!?!
end if
set eq_list to eq_list & next_val
--{8.97413217984625E+22,"+",1.0}
log next_val
end repeat
set final_val to ""
repeat with i from 1 to (count eq_list)
if item i of eq_list is "+" then
--watch for line break!
set new_val to ((item (i - 1) of eq_list) + (item (i + 1) of
eq_list))
--8.97413217984625E+22 + 1.0
set item i of eq_list to new_val
set final_val to item i of eq_list
end if
end repeat
display dialog "The answer:" default answer final_val
--default answer 8.97413217984625E+22
I must be forgetting something, but to me it seems like AppleScript is doing
what it just told me in the other script what it could not. Comments? TIA
Stephen Swift
email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.