I am hoping someone has already devised a more efficient way to accomplish this. I want to include the file size of a bunch of photos in a catalog database. Of course, I don’t want some 7 or 8 digit thing there, I want something like 1.23 MB or 0.567 MB instead. So, I came up with this handler, which receives the size of the file as determined by the Finder, and returns a 3 digit number, so long as it is over 1.0 MB:
on MakeNumber(n) set nm to (((n) / 1048576) * 100 as integer) set ns to nm as string set nl to every character of ns set fl to items 1 thru -3 of nl set fll to fl & "." & (items -2 thru -1 of nl) set fn to fll as string return fn as real end MakeNumber
The only way I could devise a modification to catch numbers less than 1 MB was this:
on MakeNumber(n) set nm to (((n) / 1048576) * 10000 as integer) set ns to nm as string set nl to every character of ns set fl to items 1 thru -4 of nl set fll to fl & "." & (items -2 thru -1 of nl) set fn to fll as string fn as real return (fn / 10) end MakeNumber
Essentially, all it does is add a 4th digit to the number, then moves the decimal over one spot to the left on the return.
It all works, but I am completely open to suggestions from anyone on a more efficient method that would cover a range of file sizes from about 400 KB up to over 25 MB.