• 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: Same code gives different answers in 2 different scripts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Same code gives different answers in 2 different scripts


  • Subject: Re: Same code gives different answers in 2 different scripts
  • From: Philip Aker <email@hidden>
  • Date: Tue, 2 Jun 2009 21:18:38 -0700

On 2009-06-01, at 17:19:35, rob wrote:

This might be my best AS stumper yet. I have a situation where the
IDENTICAL code gives different answers in two different scripts.

Here's the code:

property form_height : ((1.75 - 0.7) * 72) --=75.6

to findRound of num given numDecimals:n
set x to 10 ^ n
return (((num * x) + 0.5) div 1) / x
end findRound

set rounded_height to findRound of form_height given numDecimals:2

When run in a Script Editor window by itself, this gives the expected
result of 75.6 (apparently trailing zeroes are trimmed).

If you need consistency, here are some 'do shell script' calls.

Round:
do shell script "tclsh <<< 'puts [expr round(" & form_height & ")]'"
do shell script "tclsh <<< 'puts [expr ceil(" & form_height & ")]'"
do shell script "tclsh <<< 'puts [expr floor(" & form_height & ")]'"

Specify a specific precision using standard 'printf' format specifications it:

do shell script "tclsh <<< 'puts [format %.2f " & form_height & "]'"

The man page for 'expr' <x-man-page://n/expr>, shows the math functions available.
The man page for 'format' is at: <x-man-page://n/format> and relies on at least a cursory reading of: <x-man-page://printf>


Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

Democracy: Two wolves and a sheep voting on lunch.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Same code gives different answers in 2 different scripts (From: rob <email@hidden>)

  • Prev by Date: How to check for and remove a photo from an iPhoto album
  • Next by Date: Re: How to check for and remove a photo from an iPhoto album
  • Previous by thread: Re: Same code gives different answers in 2 different scripts
  • Next by thread: Re: Same code gives different answers in 2 different scripts
  • Index(es):
    • Date
    • Thread