Player12
An open source football management simulator
Loading...
Searching...
No Matches
NumberFormat Namespace Reference

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).
 

Detailed Description

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.

Enumeration Type Documentation

◆ MoneyError

enum class NumberFormat::MoneyError : uint8_t
strong

Why a money text was refused.

Enumerator
NONE 
EMPTY 

Nothing but blanks or a currency sign.

INVALID 

Letters, signs or symbols that are not part of an amount.

AMBIGUOUS 

Separators that could mean two different amounts.

TOO_LARGE 

Beyond any amount the game can hold.

Function Documentation

◆ current()

const Locale & NumberFormat::current ( )

Conventions of the language loaded now.

◆ decimal()

std::string NumberFormat::decimal ( double  value,
int  digits,
const Locale &  locale 
)

Fixed decimals with the decimal mark, e.g. "7.5" / "7,5".

◆ errorKey()

const char * NumberFormat::errorKey ( MoneyError  error)

Language key explaining a parse error (nullptr for NONE).

◆ grouped()

std::string NumberFormat::grouped ( int64_t  value,
const Locale &  locale 
)

Integer with grouping marks, e.g. "38,500" / "38.500".

◆ money()

std::string NumberFormat::money ( int64_t  amount,
const Locale &  locale 
)

Compact money, e.g. "€12.4M", "€850K", "-€3.1M", "€ 1,5 mln".

◆ moneyFull()

std::string NumberFormat::moneyFull ( int64_t  amount,
const Locale &  locale 
)

Full money, e.g. "€1,250,000" / "€ 1.250.000".

◆ parseMoney()

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.