I want the size of selected file/folder in MB and GB.
I want them to be in two decimals (and no decimal places if both decimal places are zeroes).
(e.g.
2480.83 MB
2.48 GB
260 MB
0.26 GB )
The below script sometimes gives me result like
4.391844E + 4 MB
42.89 GB
Please help me correct it.
set newline to ASCII character 10
tell application "Finder"
repeat with aitem in (get selection)
set textString to (size of aitem) / (1024 * 1024 / 100)
set textString to round textString
set textString1 to (textString / 100) & " MB" as text
set textString2 to (round (textString / 1024)) / 100
set textString2 to (textString2 & " GB") as text
set textString3 to textString1 & newline & textString2
end repeat
end tell
tell application "Finder" to set theSize to size of disk 1
set textString1 to formatSize(theSize, "MB")
set textString2 to formatSize(theSize, "GB")
set textString3 to textString1 & return & textString2
on formatSize(value, mode)
if mode = "MB" then
set value to value / (1024 ^ 2)
else if mode = "GB" then
set value to value / (1024 ^ 3)
end if
if value > 1000.0 then
return ((round value) as text) & space & mode
else
return (((round (value * 100)) / 100) as text) & space & mode
end if
end formatSize