MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / formatScalarForColumn

Function formatScalarForColumn

pj_widgets/src/CurveTreeView.cpp:903–924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901}
902
903QString formatScalarForColumn(double value, int precision) {
904 if (!std::isfinite(value)) {
905 return QStringLiteral("-");
906 }
907 // Fixed precision keeps a constant fractional width; then overwrite trailing
908 // zeros — and a bare trailing '.' once all decimals are blanked — with spaces.
909 // The single appended space + a right-aligned monospace cell line up every
910 // decimal point across rows (e.g. 1.2 -> "1.2 ", 5 -> "5 ").
911 QString text = QString::number(value, 'f', precision);
912 const int dot = text.indexOf(QLatin1Char('.'));
913 if (dot >= 0) {
914 int idx = text.size() - 1;
915 while (idx > dot && text[idx] == QLatin1Char('0')) {
916 text[idx] = QLatin1Char(' ');
917 --idx;
918 }
919 if (idx == dot) {
920 text[idx] = QLatin1Char(' ');
921 }
922 }
923 return text + QLatin1Char(' ');
924}
925
926} // namespace PJ

Callers 2

TESTFunction · 0.85
fillValuesNowMethod · 0.85

Calls 2

indexOfMethod · 0.80
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68