fmtlib 支持本地化,主要是控制 千分位符号。
主要API
默认情况下,所有格式都与区域设置无关。
使用“L”格式说明符从区域设置中插入适当的数字分隔符字符:
template<typename Locale, typename ...T>
auto fmt::format(const Locale &loc, format_string<T...> fmt, T&&... args) -> std::string
template<typename OutputIt, typename Locale, typename ...T>
auto fmt::format_to(OutputIt out, const Locale &loc, format_string<T...> fmt, T&&... args) -> OutputIt
template<typename Locale, typename ...T>
auto fmt::formatted_size(const Locale &loc, format_string<T...> fmt, T&&... args) -> size_t
测试代码:
#include <iostream>
#include <fmt/format.h>
#include <locale>
using namespace std;
int main(int argc, char** argv)
{
std::locale::global(std::locale("en_US.UTF-8"));
auto s = fmt::format("{:L}", 1000000); // s == "1,000,000"
cout << s << endl;
auto s2 = fmt::format(std::locale("en_US.UTF-8"), "{:L}", 1234567890);
cout << s2 << endl;
// s2 == "1,234,567,890"
return 0;
}
运行结果如下: