Re: Number of Decimal Places
Re: Number of Decimal Places
- Subject: Re: Number of Decimal Places
- From: Matthew Stuckwisch <email@hidden>
- Date: Mon, 22 Apr 2002 15:35:00 -0500
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.
For instance, "1" would be 0, "1.1" would be 2, "1.11" would be 3, etc.
Using the following guide, I'd like to know who can come up with the
fewest lines of code to return the correct number of decimal places:
--Use this code:
set x to (the text returned of (display dialog "Number:" default
answer "")) as real
--Code
display dialog "The number of decimal places of " & x & " is " &
decimalplaces
Good luck.
Well, I can do it by adding one line and editting one of your lines if you
don't make me set the TID back.
set x to (the text returned of (display dialog "Number:" default
answer "")) as real
set AppleScript's text item delimiters to "."
display dialog "The number of decimal places of " & x & " is " & (length
of (text item 2 of (x as string)))
Otherwise I have to add one more line
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
Matthew Stuckwisch
[AIM/MSN]{GuifaSwimmer} | [Yahoo!]{SapphireTree} | [ICQ]{137477701}
[IRC]{guifa / G}(esperNET / irc.massinova.com)
_______________________________________________
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.