You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
653 B
33 lines
653 B
#pragma once |
|
|
|
#include <string> |
|
|
|
#include <fmt/format.h> |
|
|
|
#include "utils/language.h" |
|
#include "utils/stdcompat/string_view.hpp" |
|
|
|
namespace devilution { |
|
|
|
/** |
|
* @brief Formats integer with thousands separator. |
|
*/ |
|
inline std::string FormatInteger(int n) |
|
{ |
|
std::string number = fmt::format("{:d}", n); |
|
std::string out = ""; |
|
|
|
int length = number.length(); |
|
int mlength = length % 3; |
|
if (mlength == 0) |
|
mlength = 3; |
|
out.append(number.substr(0, mlength)); |
|
for (int i = mlength; i < length; i += 3) { |
|
AppendStrView(out, _(/* TRANSLATORS: Thousands separator */ ",")); |
|
out.append(number.substr(i, 3)); |
|
} |
|
|
|
return out; |
|
} |
|
|
|
} // namespace devilution
|
|
|