Re: How do I format a number or Round a number?
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:07:43 +1000
On Saturday, October 11, 2003, at 02:49 AM, Work wrote:
I am trying to get Applescript to get the size of my Hard drive in a
display dialog...
...I would like to display as a
rounded number. Maybe "1.57GB" Any help would be greatly appreciated.
Try this, from The FooDoo Lounge
<
http://home.netc.net.au/~sunreal/FooDooLounge/code/numerics.html
#convertByteSize>. Watch for line wraps.
-- 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 B,
if it b % 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 b % 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 b % 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"
Cheers,
Mondo Numero
_______________________________________________
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.