Re: Crunch numbers
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.