|
|
@@ -151,14 +151,23 @@ data_type divide(data_type & remainder, data_type const & divisor) {
|
|
|
}
|
|
|
|
|
|
std::string apply(number_format const & fmt, std::string text) {
|
|
|
+ auto decimal_place = text.find('.');
|
|
|
if (fmt.separate_thousands) {
|
|
|
constexpr std::size_t const LEN_THOUSAND{3};
|
|
|
- auto pos = std::min(text.size(), text.find('.'));
|
|
|
+ auto pos = std::min(text.size(), decimal_place);
|
|
|
for (pos -= LEN_THOUSAND; pos > LEN_THOUSAND; pos -= LEN_THOUSAND) {
|
|
|
text.insert(pos, ",");
|
|
|
}
|
|
|
if (pos) { text.insert(pos, ","); }
|
|
|
}
|
|
|
+ if (decimal_place < text.size() &&
|
|
|
+ fmt.decimal_precision != std::numeric_limits<size_t>::max()) {
|
|
|
+ auto pos = decimal_place + 1 + fmt.decimal_precision;
|
|
|
+ if (fmt.decimal_precision > 0 && pos + 1 < text.size()) {
|
|
|
+ if (strchr("56789", text[pos + 1])) { ++text[pos]; }
|
|
|
+ }
|
|
|
+ text.erase(pos, std::string::npos);
|
|
|
+ }
|
|
|
return text;
|
|
|
}
|
|
|
}}
|