• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Number of Decimal Places
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number of Decimal Places


  • Subject: Re: Number of Decimal Places
  • From: Matthew Stuckwisch <email@hidden>
  • Date: Mon, 22 Apr 2002 18:49:52 -0500

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

Bah, you stole my idea of using set {a,b,c} to {1,2,3} style answers and just made the "more obfuscated"...but alas, I admit defeat (for the sake of reading and editting code ;) )


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.

References: 
 >Re: Number of Decimal Places (From: has <email@hidden>)

  • Prev by Date: Re: OS X AND TypeText (You CAN do it with Youpi Key 1.7)
  • Next by Date: Read file questions ... again!
  • Previous by thread: Re: Number of Decimal Places
  • Next by thread: Re: Number of Decimal Places
  • Index(es):
    • Date
    • Thread