• 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: Crunch numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crunch numbers


  • Subject: Re: Crunch numbers
  • From: Mark Butcher <email@hidden>
  • Date: Wed, 13 Mar 2002 07:35:26 -0800

Peter

I can't think of a solution without using text item delimiters to truncate the number.

set x to "2.84"
set y to "135.7"
set z to y / x as string
set AppleScript's text item delimiters to "."
set int to text item 1 of z as integer --integer part
set frac to ("0." & (text item 2 of z)) as real --fractional part number
set AppleScript's text item delimiters to ""
set frac to (round (frac * 10) rounding up) / 10 --round up to 1 decimal place
set z to int + frac --reassemble number

--Result: 47.8

Note:
1. The decimal point I've used is the period, not comma. I can't get Script Editor to accept commas as the decimal point.
2. The two 10's on the second to last line set the rounding precision. It could be made into a variable.
_______________________________________________
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.
  • Follow-Ups:
    • Re: Crunch numbers
      • From: Emmanuel <email@hidden>
References: 
 >Crunch numbers (From: email@hidden)

  • Prev by Date: Re: A Difference of Months
  • Next by Date: Re: A Difference of Months
  • Previous by thread: Crunch numbers
  • Next by thread: Re: Crunch numbers
  • Index(es):
    • Date
    • Thread