| 89 | static const std::locale * system_loc = try_get_locale(""); |
| 90 | |
| 91 | DFHACK_EXPORT void imbue_with_locale(std::ostringstream &ss, NumberFormatType type) { |
| 92 | if (type == NumberFormatType::ENGLISH || type == NumberFormatType::SYSTEM) { |
| 93 | try { |
| 94 | if (english_loc && type == NumberFormatType::ENGLISH) |
| 95 | ss.imbue(*english_loc); |
| 96 | else if (system_loc && type == NumberFormatType::SYSTEM) |
| 97 | ss.imbue(*system_loc); |
| 98 | } catch (std::exception &e) { |
| 99 | std::cerr << e.what() << std::endl; |
| 100 | } |
| 101 | } |
| 102 | if (type != NumberFormatType::SCIENTIFIC) |
| 103 | ss << std::fixed; |
| 104 | ss << std::setprecision(2); |
| 105 | } |
| 106 | |
| 107 | // magnitude to (suffix, divisor) |
| 108 | static const std::vector<std::pair<const char *, double>> sig_fig_db = { |