• 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: Richard Morton <email@hidden>
  • Date: Sat, 11 Oct 2003 11:30:54 +1000

Oops. Forgot about Obstreperous Server Mangulation(TM) & the url had a space in it.

The correct url is:

<http://home.netc.net.au/~sunreal/FooDooLounge/code/ numerics.html#convertByteSize>

And I'll try the routine again:

-- 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 & " KB") as string
else
return (it & " bytes") as string
end if
end convertByteSize

To call it:

set displaySize to convertByteSize on 1.66E+9
--> "1.57 GB"


Mondo Wok
-- deep fried pop
_______________________________________________
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: Richard Morton <email@hidden>)

  • Prev by Date: Re: How do I format a number or Round a number?
  • Next by Date: Re: application file of remote app broken
  • 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