Pixel-Composer/scripts/string_formatting/string_formatting.gml

19 lines
425 B
Text
Raw Normal View History

2024-11-24 11:39:17 +01:00
function string_lead_zero(val, digit, _pad = "0") {
2022-11-14 03:16:15 +01:00
var len = string_length(string(val));
var zer = digit - len;
var ss = "";
2024-11-24 11:39:17 +01:00
repeat(zer) ss += _pad;
2022-11-14 03:16:15 +01:00
ss += string(val);
return ss;
2024-04-09 05:32:00 +02:00
}
function string_byte_format(bytes) {
static suffix = [ "B", "KB", "MB", "GB", "TB" ];
var lv = clamp(floor(log2(bytes) / 10), 0, array_length(suffix) - 1);
var amo = bytes / power(2, lv * 10);
return $"{amo} {suffix[lv]}"
2022-11-14 03:16:15 +01:00
}