#define KILOBYTE_FACTOR (G_GOFFSET_CONSTANT (1024))
#define MEGABYTE_FACTOR (KILOBYTE_FACTOR * KILOBYTE_FACTOR)
7 #define GIGABYTE_FACTOR (MEGABYTE_FACTOR * KILOBYTE_FACTOR)
#define TERABYTE_FACTOR (GIGABYTE_FACTOR * KILOBYTE_FACTOR)
#define PETABYTE_FACTOR (TERABYTE_FACTOR * KILOBYTE_FACTOR)
#define EXABYTE_FACTOR (PETABYTE_FACTOR * KILOBYTE_FACTOR)
char *
g_format_size_for_display (goffset size)
{
if (size < (goffset) KILOBYTE_FACTOR)
return g_strdup_printf (g_dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size), (guint) size);
else
{
gdouble displayed_size;
if (size < (goffset) MEGABYTE_FACTOR)
{
displayed_size = (gdouble) size / (gdouble) KILOBYTE_FACTOR;
return g_strdup_printf (_("%.1f KB"), displayed_size);
}
else if (size < (goffset) GIGABYTE_FACTOR)
{
displayed_size = (gdouble) size / (gdouble) MEGABYTE_FACTOR;
return g_strdup_printf (_("%.1f MB"), displayed_size);
}
else if (size < (goffset) TERABYTE_FACTOR)
{
displayed_size = (gdouble) size / (gdouble) GIGABYTE_FACTOR;
return g_strdup_printf (_("%.1f GB"), displayed_size);
}
else if (size < (goffset) PETABYTE_FACTOR)
{
displayed_size = (gdouble) size / (gdouble) TERABYTE_FACTOR;
return g_strdup_printf (_("%.1f TB"), displayed_size);
}
else if (size < (goffset) EXABYTE_FACTOR)
{
displayed_size = (gdouble) size / (gdouble) PETABYTE_FACTOR;
return g_strdup_printf (_("%.1f PB"), displayed_size);
}
else
{
displayed_size = (gdouble) size / (gdouble) EXABYTE_FACTOR;
return g_strdup_printf (_("%.1f EB"), displayed_size);
}
}
}
阅读(1219) | 评论(0) | 转发(0) |