7 const static float BYTE_UNIT_SIZE = 1024.0;
9 const static string FORMAT_B =
"#AR-DataSize_B";
10 const static string FORMAT_KB =
"#AR-DataSize_kB";
11 const static string FORMAT_MB =
"#AR-DataSize_MB";
12 const static string FORMAT_GB =
"#AR-DataSize_GB";
16 static string ReadableSizeFromBytes(out
float value,
int decimals = 1)
21 float valCheck = value;
23 while (value > BYTE_UNIT_SIZE && count < safeCount)
25 value /= BYTE_UNIT_SIZE;
30 if (value * 0.001 > 1)
41 float dec = Math.Pow(10, decimals);
42 float valueMult10 = Math.Ceil(value * dec);
44 if (valueMult10 <= dec)
45 value = valueMult10 / dec;
47 value = valueMult10 / dec;
54 case 0:
return FORMAT_B;
break;
57 case 1:
return FORMAT_KB;
break;
60 case 2:
return FORMAT_MB;
break;
63 case 3:
return FORMAT_GB;
break;
73 static string GetReadableSize(
float value,
int decimals = 1)
75 string unit =
SCR_ByteFormat.ReadableSizeFromBytes(value, decimals);
76 return WidgetManager.Translate(unit, value);
82 static string GetReadableSizeMb(
float value)
84 float mb = 1024.0*1024.0;
85 float sizeMb = value / mb;
89 int sizeMbMult10 = Math.Ceil(sizeMb * 10.0);
91 if (sizeMbMult10 <= 10)
92 sizeMb = sizeMbMult10 / 10;
94 return WidgetManager.Translate(FORMAT_MB, sizeMb);
97 return WidgetManager.Translate(FORMAT_MB, Math.Round(sizeMb));
102 static string ContentDownloadFormat(
float value)
105 string size = value.ToString();
112 size = value.ToString(-1, dec);
113 return WidgetManager.Translate(unit, size);