MCPcopy Create free account
hub / github.com/DigitalInBlue/Celero / PrintStrColumnAligned

Function PrintStrColumnAligned

src/Print.cpp:150–176  ·  view source on GitHub ↗

http://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c Convert double to string with specified number of places after the decimal.

Source from the content-addressed store, hash-verified

148/// Convert double to string with specified number of places after the decimal.
149///
150std::string PrintStrColumnAligned(const std::string& x, const size_t width = PrintConstants::ColumnWidth, bool alignLeft = true)
151{
152 std::stringstream ss;
153 ss << std::fixed << (alignLeft ? std::left : std::right);
154
155 // fill space around displayed #
156 ss.fill(' ');
157
158 // set width around displayed #
159 ss.width(width);
160
161 if(x.length() > width)
162 {
163 // Truncate
164 std::string xTrunc = x;
165 xTrunc = xTrunc.substr(0, width);
166 ss << xTrunc;
167 }
168 else
169 {
170 ss << x;
171 }
172
173 celero::console::SetConsoleColor(celero::console::ConsoleColor::Default);
174 ss << " | ";
175 return ss.str();
176}
177
178std::string PrintColumn(const std::string& x, const size_t width = PrintConstants::ColumnWidth)
179{

Callers 2

PrintColumnFunction · 0.85
PrintColumnRightFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected