Fraction Maker Revisited Solved?
Fraction Maker Revisited Solved?
- Subject: Fraction Maker Revisited Solved?
- From: Jason Bourque <email@hidden>
- Date: Sat, 06 Nov 2004 21:59:58 -0500
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