|
|
@@ -5,11 +5,11 @@
|
|
|
// Created by Sam Jaffe on 7/4/17.
|
|
|
//
|
|
|
|
|
|
-#include "math/bignum_helper.h"
|
|
|
+#include "bignum_helper.h"
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
-using namespace math::detail;
|
|
|
+#include "math/number_format.h"
|
|
|
|
|
|
namespace {
|
|
|
constexpr int32_t const MAX_SEG{999999999};
|
|
|
@@ -149,4 +149,16 @@ data_type divide(data_type & remainder, data_type const & divisor) {
|
|
|
} while (compare(remainder, divisor) >= 0);
|
|
|
return accum;
|
|
|
}
|
|
|
+
|
|
|
+std::string apply(number_format const & fmt, std::string text) {
|
|
|
+ if (fmt.separate_thousands) {
|
|
|
+ constexpr std::size_t const LEN_THOUSAND{3};
|
|
|
+ auto pos = std::min(text.size(), text.find('.'));
|
|
|
+ for (pos -= LEN_THOUSAND; pos > LEN_THOUSAND; pos -= LEN_THOUSAND) {
|
|
|
+ text.insert(pos, ",");
|
|
|
+ }
|
|
|
+ if (pos) { text.insert(pos, ","); }
|
|
|
+ }
|
|
|
+ return text;
|
|
|
+}
|
|
|
}}
|