• 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: Nigel Garvey <email@hidden>
  • Date: Tue, 23 Apr 2002 02:11:11 +0100

Goldfish wrote on Mon, 22 Apr 2002 16:00:37 -0400:

>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:

This is nonsense. Do you mean the number of decimal places? In which
case, "1.1" would be 1, "1.11" would be 2, etc. Do you mean the number of
decimal digits? In which case, "1" would be 1.

>--Use this code:
>set x to (the text returned of (display dialog "Number:" default
>answer "")) as real

-- Coercion to real cannot produce an integer like 1
-- Coercion to number can - given the right input -
-- in which case, the following would produce the described effect:

set decimalplaces to (count (x div 1 as string) & x mod 1) - 2

>display dialog "The number of decimal places of " & x & " is " &
>decimalplaces

NG
_______________________________________________
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.

  • Prev by Date: Re: applescript-users digest, Vol 3 #377 - 15 msgs
  • Next by Date: Re: Password input
  • Previous by thread: Re: Number of Decimal Places
  • Next by thread: Apple Satire (not really) Off Topic
  • Index(es):
    • Date
    • Thread