• 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: String to sum -- another method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String to sum -- another method


  • Subject: Re: String to sum -- another method
  • From: Johnny AppleScript <email@hidden>
  • Date: Tue, 12 Oct 2004 23:37:20 -0600

Title: Re: String to sum -- another method
OK, I took another run at man bc and saw what I was missing (though I still don't quite get the use of '/n') to make this work well for me; here's a sample handler for others interested; it can take any logical _expression_ of a mathematic problem, followed by the desired number of decimal points (in this case, 10) to return:

set theProblem to "(4+5) / 2.2"
set theResult to solveProblem(theProblem, 10)
return theResult

on solveProblem(p, f)
    
set theScale to "scale=" & (f as string) & "; "
    
set qt to "\""
    
set theMath to "echo " & qt & theScale & p & qt & " | bc"
    
do shell script theMath
end solveProblem

-- >
"4.0909090909"

HTH -- JA
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: String to sum -- another method
      • From: Emmanuel <email@hidden>
References: 
 >Re: String to sum (From: Johnny AppleScript <email@hidden>)

  • Prev by Date: Re: String to sum
  • Next by Date: Re: Passing calls to an AS app via shell?
  • Previous by thread: Re: String to sum
  • Next by thread: Re: String to sum -- another method
  • Index(es):
    • Date
    • Thread