|
Player12
An open source football management simulator
|
Numbers and money in the conventions of the current language. More...
Classes | |
| struct | Locale |
| Separators and money units of one language. More... | |
| struct | MoneyParse |
| Result of parseMoney(): a value, or the reason it has none. More... | |
Enumerations | |
| enum class | MoneyError : uint8_t { NONE , EMPTY , INVALID , AMBIGUOUS , TOO_LARGE } |
| Why a money text was refused. More... | |
Functions | |
| const Locale & | current () |
| Conventions of the language loaded now. | |
| std::string | grouped (int64_t value, const Locale &locale=current()) |
| Integer with grouping marks, e.g. "38,500" / "38.500". | |
| std::string | decimal (double value, int digits, const Locale &locale=current()) |
| Fixed decimals with the decimal mark, e.g. "7.5" / "7,5". | |
| std::string | money (int64_t amount, const Locale &locale=current()) |
| Compact money, e.g. "€12.4M", "€850K", "-€3.1M", "€ 1,5 mln". | |
| std::string | moneyFull (int64_t amount, const Locale &locale=current()) |
| Full money, e.g. "€1,250,000" / "€ 1.250.000". | |
| MoneyParse | parseMoney (std::string_view text, const Locale &locale=current()) |
| Reads a typed amount: "1,5M", "1.5M", "1.500.000", "1,500,000", "1500k", "€ 2,25 mln", "850 mila", "3 mld". | |
| const char * | errorKey (MoneyError error) |
| Language key explaining a parse error (nullptr for NONE). | |
Numbers and money in the conventions of the current language.
The marks and money units come from the language file (NUMBER_* and MONEY_* keys), so English shows "€1.5M" and "1,250,000" while Italian shows "€ 1,5 mln" and "1.250.000". Parsing accepts both conventions and refuses input whose separators could mean two different amounts.
|
strong |
| const Locale & NumberFormat::current | ( | ) |
Conventions of the language loaded now.
| std::string NumberFormat::decimal | ( | double | value, |
| int | digits, | ||
| const Locale & | locale | ||
| ) |
Fixed decimals with the decimal mark, e.g. "7.5" / "7,5".
| const char * NumberFormat::errorKey | ( | MoneyError | error | ) |
Language key explaining a parse error (nullptr for NONE).
| std::string NumberFormat::grouped | ( | int64_t | value, |
| const Locale & | locale | ||
| ) |
Integer with grouping marks, e.g. "38,500" / "38.500".
| std::string NumberFormat::money | ( | int64_t | amount, |
| const Locale & | locale | ||
| ) |
Compact money, e.g. "€12.4M", "€850K", "-€3.1M", "€ 1,5 mln".
| std::string NumberFormat::moneyFull | ( | int64_t | amount, |
| const Locale & | locale | ||
| ) |
Full money, e.g. "€1,250,000" / "€ 1.250.000".
| MoneyParse NumberFormat::parseMoney | ( | std::string_view | text, |
| const Locale & | locale = current() |
||
| ) |
Reads a typed amount: "1,5M", "1.5M", "1.500.000", "1,500,000", "1500k", "€ 2,25 mln", "850 mila", "3 mld".
A mark followed by one or two digits, or the only mark before a unit, is a decimal mark; marks between groups of three digits group thousands. "14.500" and "14,500" are 14,500 in both languages (money has no third decimal). A single mark before three digits and a unit ("1.500k") is a decimal mark only when it is the language's own; otherwise the text is refused as ambiguous. Grouped numbers with a unit are refused as well.