36
36
return result / data.length;
39
// for SI units as g_format_size_for_display uses base 2
40
public string format_size(double val) {
41
const string[] units = {
42
// TRANSLATORS: Please leave {} as it is, it is replaced by the size
44
// TRANSLATORS: Please leave {} as it is, it is replaced by the size
46
// TRANSLATORS: Please leave {} as it is, it is replaced by the size
50
while (index + 1 < units.length && val >= 1000) {
55
return ngettext("%u byte", "%u bytes", (ulong)val).printf((uint)val);
56
// 4 significant digits
57
var pattern = _(units[index]).replace("{}",
58
val < 9.9995 ? "%.3f" :
59
val < 99.995 ? "%.2f" :
60
val < 999.95 ? "%.1f" : "%.0f");
61
return pattern.printf(val);
64
public string format_speed(double val) {
65
const string[] units = {
66
// TRANSLATORS: Please leave {} as it is, it is replaced by the speed
68
// TRANSLATORS: Please leave {} as it is, it is replaced by the speed
70
// TRANSLATORS: Please leave {} as it is, it is replaced by the speed
72
// TRANSLATORS: Please leave {} as it is, it is replaced by the speed
76
while (index + 1 < units.length && val >= 1000) {
81
return ngettext("%u byte/s", "%u bytes/s", (ulong)val).printf((uint)val);
82
// 4 significant digits
83
var pattern = _(units[index]).replace("{}",
84
val < 9.9995 ? "%.3f" :
85
val < 99.995 ? "%.2f" :
86
val < 999.95 ? "%.1f" : "%.0f");
87
return pattern.printf(val);