This is an alias i created for going with my uTorrent add-on but i thought i'd release it on here as it's quite handy
Usage: $b2m(N,[inp])[.out]
Where the values "N", "inp" and ".out" represent;
N = The size in bytes.
inp = NOT MANDATORY; The input, if the value of N is NOT in bytes, enter the type here, "kb","mb","gb". Else the script will presume N is in bytes.
.out = NOT MANDATORY; But if you want it specifically in a certain output switch ".out" to ".b",".kb",".mb","gb". Else the script will output the most appropriate type.
Using input without ouput of course is pretty useless at will just resolve the same number as you entered.
For example;
$b2m(1024).kb
---
1 KB
$b2m(1,gb).mb
---
1024 MB
alias b2m {
; Usage: $b2m(N,[inp])[.out]
; Where the values "N", "inp" and ".out" represent;
; N = The size in bytes.
; inp = NOT MANDATORY; The input, if the value of N is NOT in bytes, enter the type here, "kb","mb","gb". Else the script will presume N is in bytes.
; .out = NOT MANDATORY; But if you want it specifically in a certain output switch ".out" to ".b",".kb",".mb","gb". Else the script will output the most appropriate type.
; Using input without ouput of course is pretty useless at will just resolve the same number as you entered.
if ($1 isnum) {
var %size = $1
if ($istok(kb mb gb,$2,32)) {
if ($2 == kb) { var %c = 1 }
if ($2 == mb) { var %c = 2 }
if ($2 == gb) { var %c = 3 }
var %x = 1
while (%x <= %c) { var %size = $calc(%size * 1024) | inc %x }
}
if ($istok(b kb mb gb,$prop,32)) { goto $prop }
if (%size <= 1024) { :b | var %val = $round(%size,2) B }
elseif ($calc(%size / 1024) <= 1024) { :kb | var %val = $round($calc(%size / 1024),2) KB }
elseif ($calc(%size / 1024 / 1024) <= 1024) { :mb | var %val = $round($calc(%size / 1024 / 1024),2) MB }
else { :gb | var %val = $round($calc(%size / 1024 / 1024 / 1024),2) GB }
return %val
}
else { return error; $iif($1,$qt($1) is not a number,no number was entered) }
}
I used this alias in for this script; http://www.hawkee.com/profile/img/2454/
in the downloaded/size etc parts.