MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / UnitsToText

Function UnitsToText

Source/Engine/Core/Utilities.h:50–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48 /// <returns>The best fitting string of the units.</returns>
49 template<typename T>
50 String UnitsToText(T units, int32 divider, const Span<const Char*> sizes)
51 {
52 if (sizes.Length() == 0)
53 return String::Format(TEXT("{0}"), units);
54 int32 i = 0;
55 double dblSUnits = static_cast<double>(units);
56 for (; static_cast<uint64>(units / static_cast<double>(divider)) > 0; i++, units /= divider)
57 dblSUnits = (double)units / (double)divider;
58 if (i >= sizes.Length())
59 i = 0;
60 String text = String::Format(TEXT("{}"), RoundTo2DecimalPlaces(dblSUnits));
61 const int32 dot = text.FindLast('.');
62 if (dot != -1)
63 text = text.Left(dot + 3);
64 return String::Format(TEXT("{0} {1}"), text, sizes[i]);
65 }
66
67 /// <summary>
68 /// Converts size of the data (in bytes) to the best fitting string.

Callers 2

BytesToTextFunction · 0.85
HertzToTextFunction · 0.85

Calls 5

RoundTo2DecimalPlacesFunction · 0.85
LeftMethod · 0.80
FormatFunction · 0.50
LengthMethod · 0.45
FindLastMethod · 0.45

Tested by

no test coverage detected