Re: Number of Decimal Places
Re: Number of Decimal Places
- Subject: Re: Number of Decimal Places
- From: has <email@hidden>
- Date: Tue, 23 Apr 2002 00:26:30 +0100
Goldfish most recklessly issued:
>
> Hi. Here is an open challenge:
>
>
>
> I would like to, in the fewest lines of code, determine the number of
>
> decimal places of a "real" named x.
To which Matthew Stuckwisch replied:
>
set x to (the text returned of (display dialog "Number:" default
>
answer "")) as real
>
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text
>
item delimiters, "."}
>
display dialog "The number of decimal places of " & x & " is " & (length
>
of (text item 2 of (x as string)))
>
set AppleScript's text item delimiters to oldTID
FOUR lines?! Bah-phooey, TWO lines easy!
======================================================================
set {oldTID, AppleScript's text item delimiters, x} to {AppleScript's
[NO-BREAK]text item delimiters, ".", (the text returned of (display
[NO-BREAK]dialog "Number:" default answer ""))}
set {y, z, AppleScript's text item delimiters} to {x as real, display
[NO-BREAK]dialog "The number of decimal places of " & x & " is " &
[NO-BREAK](length of (text item 2 of (x & "."))), oldTID}
======================================================================
This is all, of course, assuming that the original challenge was for the
most obfuscated answer, not the most readable one. :p
has
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.