• 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: How do I format a number or Round a number?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I format a number or Round a number?


  • Subject: Re: How do I format a number or Round a number?
  • From: John Cochrane <email@hidden>
  • Date: Sun, 12 Oct 2003 14:24:59 +1000

On Sunday, October 12, 2003, at 12:18 AM, Nigel Garvey wrote:

If you want to mimic the current Finder information window
interpretations:

to convertByteSize from theRawSize
set oneK to 2 ^ 10
set oneMB to 2 ^ 20
set oneGB to 2 ^ 30
if theRawSize >= oneGB then
((theRawSize / oneGB * ((10 ^ 0.5) ^ 2) div 0.1 / 100) as string) &
" GB"
else if theRawSize >= oneMB then
((theRawSize / oneMB * ((10 ^ 0.5) ^ 2) div 0.1 / 100) as string) &
" MB"
else if theRawSize >= oneK then
((theRawSize div oneK) as string) & " KB"
else
return (theRawSize as string) & " bytes"
end if
end convertByteSize

tell application "Finder" to get capacity of startup disk
convertByteSize from result


The above is probably cleaner and more accurate than than code below that I have been using to get the size to 1 decimal place

tell application "Finder"
set _size to size of (choose folder)
end tell
roundsize(_size)


on roundsize(_bytes)
if _bytes > 1.073741824E+9 then
set _bytes to _bytes / 1.073741824E+9
set _units to "GB"

else if _bytes < 1.073741824E+9 and _bytes > 1048576 then
set _bytes to _bytes / 1048576
set _units to "MB"

else if _bytes < 1048576 and _bytes > 1024 then
set _bytes to _bytes / 1024
set _units to "KB"
else
set _bytes to _bytes / 1
set _units to "bytes"
end if
set sizeValue to (round (_bytes * 10)) / 10
return {sizeValue, _units}
end roundsize


However I find that they both have problems if used to get the size of a folder.
The first time that the scripts are run they return a missing value. If repeated they return a result but this does not agree with the size given in the folders "Info" window


best wishes

John
_______________________________________________
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.

References: 
 >Re: How do I format a number or Round a number? (From: Nigel Garvey <email@hidden>)

  • Prev by Date: Follow-up: files in subfolders (was Re: file type question)
  • Next by Date: get seconds
  • Previous by thread: Re: How do I format a number or Round a number?
  • Next by thread: Re: How do I format a number or Round a number?
  • Index(es):
    • Date
    • Thread