| 901 | } |
| 902 | |
| 903 | QString 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 |