Skip to content

FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.

ui: compact volume formatting in watchlist + shared NumberFormat header

Sujallukhi044dee2b60788c
diff --git a/fincept-qt/src/screens/markets/MarketPanel.cpp b/fincept-qt/src/screens/markets/MarketPanel.cpp
index c2e93857e..cdf364aba 100644
--- a/fincept-qt/src/screens/markets/MarketPanel.cpp
+++ b/fincept-qt/src/screens/markets/MarketPanel.cpp
@@ -2,6 +2,7 @@
#include "ui/theme/Theme.h"
#include "ui/theme/ThemeManager.h"
+#include "ui/formatting/NumberFormat.h"
# include "datahub/DataHub.h"
# include "datahub/DataHubMetaTypes.h"
@@ -364,7 +365,7 @@ void MarketPanel::populate(const QVector<services::QuoteData>& quotes) {
else if (col == "CHG%") table_->setItem(row, ci, mk(QString("%1%2%").arg(arr).arg(std::abs(q.change_pct), 0, 'f', 2), cc));
else if (col == "HIGH") table_->setItem(row, ci, mk(QString::number(q.high, 'f', 2), ui::colors::TEXT_SECONDARY()));
else if (col == "LOW") table_->setItem(row, ci, mk(QString::number(q.low, 'f', 2), ui::colors::TEXT_SECONDARY()));
- else if (col == "VOL") table_->setItem(row, ci, mk("--", ui::colors::TEXT_DIM())); // TODO: wire volume from API response
+ else if (col == "VOL") table_->setItem(row, ci, mk(fincept::ui::formatting::format_compact_volume(static_cast<qint64>(q.volume)), ui::colors::TEXT_DIM()));
else if (col == "BID") table_->setItem(row, ci, mk("--", ui::colors::TEXT_DIM()));
else if (col == "ASK") table_->setItem(row, ci, mk("--", ui::colors::TEXT_DIM()));
else if (col == "OPEN") table_->setItem(row, ci, mk("--", ui::colors::TEXT_DIM()));
diff --git a/fincept-qt/src/screens/watchlist/WatchlistScreen.cpp b/fincept-qt/src/screens/watchlist/WatchlistScreen.cpp
index 527c2b4ef..15453704c 100644
--- a/fincept-qt/src/screens/watchlist/WatchlistScreen.cpp
+++ b/fincept-qt/src/screens/watchlist/WatchlistScreen.cpp
@@ -7,6 +7,7 @@
#include "core/symbol/SymbolDragSource.h"
#include "ui/theme/Theme.h"
#include "ui/theme/ThemeManager.h"
+#include "ui/formatting/NumberFormat.h"
# include "datahub/DataHub.h"
# include "datahub/DataHubMetaTypes.h"
@@ -559,7 +560,7 @@ void WatchlistScreen::populate_table(const QVector<services::QuoteData>& quotes)
QString("%1%2").arg(q.change >= 0 ? "+" : "").arg(q.change, 0, 'f', 2),
QString("%1%2%").arg(q.change_pct >= 0 ? "+" : "").arg(q.change_pct, 0, 'f', 2),
QString("$%1").arg(q.high, 0, 'f', 2), QString("$%1").arg(q.low, 0, 'f', 2),
- QString::number(static_cast<qint64>(q.volume))});
+ fincept::ui::formatting::format_compact_volume(static_cast<qint64>(q.volume))});
int row = table_->rowCount() - 1;
// Green = good, Red = bad
@@ -718,7 +719,7 @@ void WatchlistScreen::on_export_csv() {
<< QString::number(q.change_pct, 'f', 2) << ','
<< QString::number(q.high, 'f', 2) << ','
<< QString::number(q.low, 'f', 2) << ','
- << QString::number(static_cast<qint64>(q.volume)) << '\n';
+ << fincept::ui::formatting::format_compact_volume(static_cast<qint64>(q.volume)) << '\n';
}
}
diff --git a/fincept-qt/src/ui/formatting/NumberFormat.h b/fincept-qt/src/ui/formatting/NumberFormat.h
new file mode 100644
index 000000000..dc2b195de
--- /dev/null
+++ b/fincept-qt/src/ui/formatting/NumberFormat.h
@@ -0,0 +1,20 @@
+#pragma once
+#include <QString>
+
+namespace fincept::ui::formatting {
+
+inline QString format_compact_volume(qint64 volume) {
+ if (volume <= 0) return "--";
+ double v = static_cast<double>(volume);
+ if (v >= 1e9) {
+ return QString::number(v / 1e9, 'f', 2) + "B";
+ } else if (v >= 1e6) {
+ return QString::number(v / 1e6, 'f', 2) + "M";
+ } else if (v >= 1e3) {
+ return QString::number(v / 1e3, 'f', 2) + "K";
+ } else {
+ return QString::number(volume);
+ }
+}
+
+} // namespace fincept::ui::formatting