Changeset - r28607:425c0f3f1a66
[Not reviewed]
master
0 2 0
Patric Stout - 10 months ago 2024-01-29 20:20:35
truebrain@openttd.org
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.
2 files changed with 25 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -5799,6 +5799,11 @@ STR_TOWN_NAME                           
 
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}
src/strings.cpp
Show inline comments
 
@@ -510,7 +510,6 @@ static void FormatGenericCurrency(String
 
	/* 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(String
 
	 * 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(String
 
	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).
0 comments (0 inline, 0 general)