Re: Exponential notation [was: Re: How to calculate/process this one?]
Re: Exponential notation [was: Re: How to calculate/process this one?]
- Subject: Re: Exponential notation [was: Re: How to calculate/process this one?]
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 27 Apr 2002 08:59:37 -0700
On 4/27/02 8:18 AM, I wrote:
>
> to Stringify(x)
>
>
>
Sorry, in my haste to be first I forgot to reset tids. Rap self on
>
knuckles.
>
Oh, dear. Then I re-set them incorrectly. Plus, I did not take account of
exponential non-integers such as 553334556.7456, where there are significant
decimal places .
OK, general case, including numbers like 27 as well:
to Stringify(x) -- for E+ numbers
set x to x as string
set {tids, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {"E+"}}
if (count (text items of x)) = 1 then
set AppleScript's text item delimiters to {tids}
return x
else
set {n, z} to {text item 1 of x, (text item 2 of x) as integer}
set AppleScript's text item delimiters to {tids}
set i to character 1 of n
set d to text 3 thru -1 of n
set l to count d
if l > z then
return (i & (text 1 thru z of d) & "." & (text (z + 1) thru -1
of d))
else
repeat (z - l) times
set d to d & "0"
end repeat
return (i & d)
end if
end if
end Stringify
set x to 5.533345567456E+8
set n to Stringify(x)
--> "553334556.7456"
set x to 5.36870912E+8
set n to Stringify(x)
--> "536870912"
set x to 1.0E+4
set n to Stringify(x)
--> "10000"
set x to 1.23456E+5
set n to Stringify(x)
--> "123456"
set x to 27
set n to Stringify(x)
--> "27"
--
Paul Berkowitz
_______________________________________________
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.