-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathStrFormatByteSizeEx.ahk
19 lines (15 loc) · 1.07 KB
/
StrFormatByteSizeEx.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
; ===============================================================================================================================
; Converts a numeric value into a string that represents the number in bytes, kilobytes, megabytes, or gigabytes,
; depending on the size. Extends StrFormatByteSizeW by offering the option to round to the nearest displayed digit
; or to discard undisplayed digits.
; ===============================================================================================================================
StrFormatByteSizeEx(int, flags := 0x2) {
size := VarSetCapacity(buf, 0x0104, 0)
if (DllCall("shlwapi.dll\StrFormatByteSizeEx", "int64", int, "int", flags, "str", buf, "uint", size) != 0)
throw Exception("StrFormatByteSizeEx failed", -1)
return buf
}
; ===============================================================================================================================
;~ MsgBox % StrFormatByteSizeEx(2400016) ; -> 2.28 MB
;~ MsgBox % StrFormatByteSizeEx(2400016, 0x1) ; -> 2.29 MB
; 2400016 / 1024 / 1024 -> 2.28883361816