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.
| 148 | /// Convert double to string with specified number of places after the decimal. |
| 149 | /// |
| 150 | std::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 | |
| 178 | std::string PrintColumn(const std::string& x, const size_t width = PrintConstants::ColumnWidth) |
| 179 | { |
no outgoing calls
no test coverage detected