Re: Fraction Maker Revisited Solved?
Re: Fraction Maker Revisited Solved?
- Subject: Re: Fraction Maker Revisited Solved?
- From: Jason Bourque <email@hidden>
- Date: Sat, 06 Nov 2004 22:10:09 -0500
Ok, one fix it now catches matches instead of going to the higher number.
I.e. .875 return 7/8 instead of 29/32
-- Jason Bourque
set vNumberToFraction to 0.875
set vBottomNumber to 32
tell me to srFractionMaker(vNumberToFraction, vBottomNumber)
on srFractionMaker(vNumberToFraction, vBottomNumber)
set vFractionFound to ""
repeat with vNth from 1 to vBottomNumber
copy vNth to vTopNumber
set vDividedNumber to vTopNumber / vBottomNumber
if vNumberToFraction is less than or equal to vDividedNumber then
repeat -- This brings ups the fraction if possible
if (vTopNumber mod 2 = 0) and (vBottomNumber mod 2 = 0) then
set vTopNumber to (vTopNumber / 2) as integer
set vBottomNumber to (vBottomNumber / 2) as integer
else
set vFractionFound to ("" & vTopNumber & "/" &
vBottomNumber) as text
exit repeat
end if
end repeat
-- Needed to escape from second repeat loop
if vFractionFound is not "" then exit repeat
end if
end repeat
-- return {vNth, vTopNumber, vNumberToFraction, vDividedNumber,
vFractionFound}
return vFractionFound
end srFractionMaker
On 11/6/04 9:59 PM, "Jason Bourque" <email@hidden> wrote:
> Hello, a few weeks back I asked for a fraction maker that would round to
> get to the nearest recognizable fraction (1/1 to 1/32). So I came up with
> this. It does comparisons instead of rounding. I know what type of fraction
> I want so I make them and compare the decimal to it. Then run a fraction
> flattening loop that brings things like 16/32 to 1/2. I like the result.
> Any thoughs on this one? Jason Bourque
>
> You can make it tighter by lowering the bottom number to 16 or 8
>
>
> set vNumberToFraction to 0.874
> set vFractionFound to ""
> set vBottomNumber to 32
>
> repeat with vNth from 1 to vBottomNumber
>
> copy vNth to vTopNumber
>
> set vDividedNumber to vTopNumber / vBottomNumber
>
> if vNumberToFraction is less than vDividedNumber then
> repeat -- This brings ups the fraction if possible
> if (vTopNumber mod 2 = 0) and (vBottomNumber mod 2 = 0) then
> set vTopNumber to (vTopNumber / 2) as integer
> set vBottomNumber to (vBottomNumber / 2) as integer
> else
> set vFractionFound to ("" & vTopNumber & "/" &
> vBottomNumber) as text
> exit repeat
> end if
> end repeat
> -- Needed to escape from second repeat loop
> if vFractionFound is not "" then exit repeat
> end if
> end repeat
>
> return {vNth, vTopNumber, vDividedNumber, vFractionFound}
>
>
> _______________________________________________
> 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
_______________________________________________
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