• 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: Formating bytes to Mbytes / Gbytes ??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Formating bytes to Mbytes / Gbytes ??


  • Subject: Re: Formating bytes to Mbytes / Gbytes ??
  • From: Richard Morton <email@hidden>
  • Date: Tue, 8 Apr 2003 16:35:28 +1000

On Tuesday, April 8, 2003, at 08:43 AM, Jakob Peterhdnsel wrote:
Does anyone have a code snippet to convert raw byte numbers into Kb, Mb & Gb values??

Try this, from The FooDoo Lounge - <http://home.netc.net.au/~sunreal/FooDooLounge/code/ numerics.html#convertByteSize> - watch for line wraps, or just copy it from the web page. It could be made a little smaller, but was designed for speed and uses some of NG's ingenious optimisations:

-- convertByteSize -- by Nigel Garvey & Richard Morton, 2002 ---- Convert bytes to a readable string in bytes-K-MB-GB as required.-- Pass the number in bytes. Returns string.to convertByteSize on theRawSize
set oneK to 2 ^ 10
set oneMB to 2 ^ 20
set oneGB to 2 ^ 30
tell theRawSize to ,
if it >= oneGB then
return ((it div oneGB) & "." & text 2 thru 3 of ((100 + ((it mod oneGB) div (oneK * 1.0E+4))) as string) & " GB") as string
else if it >= oneMB then
return ((it div oneMB) & "." & text 2 thru 3 of ((100 + ((it mod oneMB) div (oneK * 10))) as string) & " MB") as string
else if it >= oneK then
return (it div oneK & " K") as string
else
return ((it as integer) & " bytes") as string
end if
end convertByteSize


set sizeString to convertByteSize on 5.98745695235E+11
--> "557.65 GB"

Cheers,

Opt E Miser
_______________________________________________
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: 
 >Formating bytes to Mbytes / Gbytes ?? (From: Jakob Peterhänsel <email@hidden>)

  • Prev by Date: Re: Universal or general path to desktop?
  • Next by Date: Re: Formating bytes to Mbytes / Gbytes
  • Previous by thread: Re: Formating bytes to Mbytes / Gbytes ??
  • Next by thread: Re: Formating bytes to Mbytes / Gbytes
  • Index(es):
    • Date
    • Thread