• 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
Decimal Place Limiting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Decimal Place Limiting


  • Subject: Decimal Place Limiting
  • From: John Amerkhanian <email@hidden>
  • Date: Tue, 1 Apr 2008 14:20:03 -0700

I wrote a small script to solve quadratic equations and it works fine until I start putting in larger numbers. I first noticed this when I put in 2, 4, 3 for a, b, c and I realized this was because my variable top1 has too many decimal places. How can I limit its decimal places to say... four?

Heres the script:

repeat
display dialog "Enter the coefficient A:" default answer "" buttons "Next" default button 1


set A to the text returned of the result as number


display dialog "Enter the coefficient B:" default answer "" buttons "Next" default button 1


set B to the text returned of the result as number


display dialog "Enter the coefficient C:" default answer "" buttons "Solve" default button 1


set C to the text returned of the result as number



set top1 to (B * B - 4 * A * C)

set top to top1 ^ (1 / 2)


set root1 to (-B + top) / (2 * A)
set root2 to (-B - top) / (2 * A)


display dialog "The solutions are: " & root1 & ", " & root2 & "" buttons {"Ok", "Do it Again"} default button 1
set theResult to the result as list
if theResult is equal to {"Ok"} then exit repeat
end repeat

 _______________________________________________
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

  • Follow-Ups:
    • Re: Decimal Place Limiting
      • From: deivy petrescu <email@hidden>
    • Re: Decimal Place Limiting
      • From: Geoff Sheehan <email@hidden>
    • Re: Decimal Place Limiting
      • From: Michelle Steiner <email@hidden>
  • Prev by Date: Re: [Sappho]
  • Next by Date: re: launching firefox
  • Previous by thread: Re: [Sappho]
  • Next by thread: Re: Decimal Place Limiting
  • Index(es):
    • Date
    • Thread