Player12
An open source football management simulator
Loading...
Searching...
No Matches
number_format.h
Go to the documentation of this file.
1
// -----------------------------------------------------------------------------
2
// Football Management Project
3
// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4
//
5
// This file is part of the Football Management Project.
6
// See the LICENSE file in the project root.
7
// -----------------------------------------------------------------------------
8
9
#pragma once
10
11
#include <cstdint>
12
#include <optional>
13
#include <string>
14
#include <string_view>
15
24
namespace
NumberFormat
25
{
26
28
struct
Locale
29
{
30
std::string
decimal_mark
=
"."
;
31
std::string
group_mark
=
","
;
33
std::string
money_pattern
=
"€{0}"
;
34
std::string
thousand_unit
=
"K"
;
35
std::string
million_unit
=
"M"
;
36
std::string
billion_unit
=
"B"
;
37
39
static
Locale
english
() {
return
{}; }
40
};
41
43
const
Locale&
current
();
44
46
std::string
grouped
(int64_t value,
const
Locale& locale =
current
());
47
49
std::string
decimal
(
double
value,
int
digits,
const
Locale& locale =
current
());
50
52
std::string
money
(int64_t amount,
const
Locale& locale =
current
());
53
55
std::string
moneyFull
(int64_t amount,
const
Locale& locale =
current
());
56
58
enum class
MoneyError
: uint8_t
59
{
60
NONE
,
61
EMPTY
,
62
INVALID
,
63
AMBIGUOUS
,
64
TOO_LARGE
,
65
};
66
68
struct
MoneyParse
69
{
70
std::optional<int64_t>
value
;
71
MoneyError
error
=
MoneyError::NONE
;
72
};
73
85
MoneyParse
parseMoney
(std::string_view text,
const
Locale
& locale =
current
());
86
88
const
char
*
errorKey
(
MoneyError
error);
89
90
}
// namespace NumberFormat
NumberFormat
Numbers and money in the conventions of the current language.
Definition
number_format.cpp:194
NumberFormat::moneyFull
std::string moneyFull(int64_t amount, const Locale &locale)
Full money, e.g. "€1,250,000" / "€ 1.250.000".
Definition
number_format.cpp:232
NumberFormat::current
const Locale & current()
Conventions of the language loaded now.
Definition
number_format.cpp:196
NumberFormat::parseMoney
MoneyParse parseMoney(std::string_view text, const Locale &locale)
Reads a typed amount: "1,5M", "1.5M", "1.500.000", "1,500,000", "1500k", "€ 2,25 mln",...
Definition
number_format.cpp:393
NumberFormat::errorKey
const char * errorKey(MoneyError error)
Language key explaining a parse error (nullptr for NONE).
Definition
number_format.cpp:425
NumberFormat::grouped
std::string grouped(int64_t value, const Locale &locale)
Integer with grouping marks, e.g. "38,500" / "38.500".
Definition
number_format.cpp:198
NumberFormat::MoneyError
MoneyError
Why a money text was refused.
Definition
number_format.h:59
NumberFormat::MoneyError::AMBIGUOUS
@ AMBIGUOUS
NumberFormat::MoneyError::TOO_LARGE
@ TOO_LARGE
NumberFormat::MoneyError::NONE
@ NONE
NumberFormat::MoneyError::EMPTY
@ EMPTY
NumberFormat::MoneyError::INVALID
@ INVALID
NumberFormat::money
std::string money(int64_t amount, const Locale &locale)
Compact money, e.g. "€12.4M", "€850K", "-€3.1M", "€ 1,5 mln".
Definition
number_format.cpp:213
NumberFormat::decimal
std::string decimal(double value, int digits, const Locale &locale)
Fixed decimals with the decimal mark, e.g. "7.5" / "7,5".
Definition
number_format.cpp:204
NumberFormat::Locale
Separators and money units of one language.
Definition
number_format.h:29
NumberFormat::Locale::english
static Locale english()
The English conventions (also the defaults above).
Definition
number_format.h:39
NumberFormat::Locale::billion_unit
std::string billion_unit
Definition
number_format.h:36
NumberFormat::Locale::group_mark
std::string group_mark
Definition
number_format.h:31
NumberFormat::Locale::money_pattern
std::string money_pattern
Definition
number_format.h:33
NumberFormat::Locale::decimal_mark
std::string decimal_mark
Definition
number_format.h:30
NumberFormat::Locale::million_unit
std::string million_unit
Definition
number_format.h:35
NumberFormat::Locale::thousand_unit
std::string thousand_unit
Definition
number_format.h:34
NumberFormat::MoneyParse
Result of parseMoney(): a value, or the reason it has none.
Definition
number_format.h:69
NumberFormat::MoneyParse::error
MoneyError error
Definition
number_format.h:71
NumberFormat::MoneyParse::value
std::optional< int64_t > value
Definition
number_format.h:70
src
global
number_format.h
Generated by
1.9.8