mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
Add: {CURRENCY_SHORT} only did k / m suffix. Add bn / tn and make translatable. (#11921)
64bit numbers are REALLY large, but our compact method was build for 32bit numbers. Extend it to 64bit.
This commit is contained in:
parent
1d4b10a8b8
commit
f1842f9144
@ -5799,6 +5799,11 @@ STR_TOWN_NAME :{TOWN}
|
||||
STR_VEHICLE_NAME :{VEHICLE}
|
||||
STR_WAYPOINT_NAME :{WAYPOINT}
|
||||
|
||||
STR_CURRENCY_SHORT_KILO :{NBSP}k
|
||||
STR_CURRENCY_SHORT_MEGA :{NBSP}m
|
||||
STR_CURRENCY_SHORT_GIGA :{NBSP}bn
|
||||
STR_CURRENCY_SHORT_TERA :{NBSP}tn
|
||||
|
||||
STR_JUST_CARGO :{CARGO_LONG}
|
||||
STR_JUST_RIGHT_ARROW :{RIGHT_ARROW}
|
||||
STR_JUST_CHECKMARK :{CHECKMARK}
|
||||
|
@ -510,7 +510,6 @@ static void FormatGenericCurrency(StringBuilder &builder, const CurrencySpec *sp
|
||||
/* We are going to make number absolute for printing, so
|
||||
* keep this piece of data as we need it later on */
|
||||
bool negative = number < 0;
|
||||
const char *multiplier = "";
|
||||
|
||||
number *= spec->rate;
|
||||
|
||||
@ -527,16 +526,24 @@ static void FormatGenericCurrency(StringBuilder &builder, const CurrencySpec *sp
|
||||
* The only remaining value is 1 (suffix), so everything that is not 1 */
|
||||
if (spec->symbol_pos != 1) builder += spec->prefix;
|
||||
|
||||
/* for huge numbers, compact the number into k or M */
|
||||
StringID number_str = STR_NULL;
|
||||
|
||||
/* For huge numbers, compact the number. */
|
||||
if (compact) {
|
||||
/* Take care of the 'k' rounding. Having 1 000 000 k
|
||||
/* Take care of the thousand rounding. Having 1 000 000 k
|
||||
* and 1 000 M is inconsistent, so always use 1 000 M. */
|
||||
if (number >= 1000000000 - 500) {
|
||||
number = (number + 500000) / 1000000;
|
||||
multiplier = NBSP "M";
|
||||
} else if (number >= 1000000) {
|
||||
number = (number + 500) / 1000;
|
||||
multiplier = NBSP "k";
|
||||
if (number >= Money(1'000'000'000'000'000) - 500'000'000) {
|
||||
number = (number + Money(500'000'000'000)) / Money(1'000'000'000'000);
|
||||
number_str = STR_CURRENCY_SHORT_TERA;
|
||||
} else if (number >= Money(1'000'000'000'000) - 500'000) {
|
||||
number = (number + 500'000'000) / 1'000'000'000;
|
||||
number_str = STR_CURRENCY_SHORT_GIGA;
|
||||
} else if (number >= 1'000'000'000 - 500) {
|
||||
number = (number + 500'000) / 1'000'000;
|
||||
number_str = STR_CURRENCY_SHORT_MEGA;
|
||||
} else if (number >= 1'000'000) {
|
||||
number = (number + 500) / 1'000;
|
||||
number_str = STR_CURRENCY_SHORT_KILO;
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,7 +551,10 @@ static void FormatGenericCurrency(StringBuilder &builder, const CurrencySpec *sp
|
||||
if (StrEmpty(separator)) separator = _currency->separator.c_str();
|
||||
if (StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator_currency;
|
||||
FormatNumber(builder, number, separator);
|
||||
builder += multiplier;
|
||||
if (number_str != STR_NULL) {
|
||||
auto tmp_params = ArrayStringParameters<0>();
|
||||
FormatString(builder, GetStringPtr(number_str), tmp_params);
|
||||
}
|
||||
|
||||
/* Add suffix part, following symbol_pos specification.
|
||||
* Here, it can can be either 1 (suffix) or 2 (both prefix and suffix).
|
||||
|
Loading…
Reference in New Issue
Block a user