aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-25 20:33:16 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-25 20:33:16 +0100
commitf5d154c2d6ca848a526562bd6a678c311ee34e6b (patch)
tree86d5e5ee765a4ae118e84b812a8fe54cfbecae68 /src/StringUtils.cpp
parent3f0473c5aa472ac99d20a46bd7217ee9b6429f62 (diff)
Thousands comma for youtube likes/dislikes and peertube views
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 494e32f..8d8b62e 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -241,4 +241,24 @@ namespace QuickMedia {
return buffer;
}
+
+ std::string number_separate_thousand_commas(const std::string &number) {
+ const int num_commas = ((int)number.size() - 1) / 3;
+ std::string result;
+ result.resize(number.size() + num_commas);
+ int result_index = (int)number.size() + num_commas - 1;
+ int inc = 0;
+
+ for(int i = (int)number.size() - 1; i >= 0; --i, ++inc) {
+ if(inc > 0 && inc % 3 == 0) {
+ result[result_index] = ',';
+ --result_index;
+ }
+
+ result[result_index] = number[i];
+ --result_index;
+ }
+
+ return result;
+ }
} \ No newline at end of file