MCPcopy Create free account
hub / github.com/IENT/YUView / formatDataSize

Function formatDataSize

YUViewLib/src/common/Functions.cpp:121–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121QString formatDataSize(double size, bool isBits)
122{
123 unsigned divCounter = 0;
124 bool isNegative = size < 0;
125 if (isNegative)
126 size = -size;
127 while (divCounter < 5 && size >= 1000)
128 {
129 size = size / 1000;
130 divCounter++;
131 }
132 QString valueString;
133 if (isNegative)
134 valueString += "-";
135 valueString += QString("%1").arg(size, 0, 'f', 2);
136
137 if (divCounter > 0 && divCounter < 5)
138 {
139 const auto bitsUnits = QStringList() << "kbit"
140 << "Mbit"
141 << "Gbit"
142 << "Tbit";
143 const auto bytesUnits = QStringList() << "kB"
144 << "MB"
145 << "GB"
146 << "TB";
147 if (isBits)
148 return QString("%1 %2").arg(valueString).arg(bitsUnits[divCounter - 1]);
149 else
150 return QString("%1 %2").arg(valueString).arg(bytesUnits[divCounter - 1]);
151 }
152
153 return valueString;
154}
155
156QStringList toQStringList(const std::vector<std::string> &stringVec)
157{

Callers 2

formatValueMethod · 0.85
formatValueMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected