diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index d626383c66..994301f7cf 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -806,7 +806,7 @@ static void window_cheats_money_mouseup(rct_window *w, rct_widgetindex widgetInd game_do_command(0, GAME_COMMAND_FLAG_APPLY, CHEAT_NOMONEY, gParkFlags & PARK_FLAGS_NO_MONEY ? 0 : 1, GAME_COMMAND_CHEAT, 0, 0); break; case WIDX_MONEY_SPINNER: - money_to_string(_moneySpinnerValue, _moneySpinnerText, MONEY_STRING_MAXLENGTH); + money_to_string(_moneySpinnerValue, _moneySpinnerText, MONEY_STRING_MAXLENGTH, false); window_text_input_raw_open(w, WIDX_MONEY_SPINNER, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, _moneySpinnerText, MONEY_STRING_MAXLENGTH); break; case WIDX_SET_MONEY: diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 8a1569a65a..cdd3022ed5 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -6047,7 +6047,7 @@ static void window_ride_income_mouseup(rct_window *w, rct_widgetindex widgetInde Ride* ride = get_ride(w->number); - money_to_string((money32)ride->price, _moneyInputText, MONEY_STRING_MAXLENGTH); + money_to_string((money32)ride->price, _moneyInputText, MONEY_STRING_MAXLENGTH, true); window_text_input_raw_open(w, WIDX_PRIMARY_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, _moneyInputText, MONEY_STRING_MAXLENGTH); break; } @@ -6057,7 +6057,7 @@ static void window_ride_income_mouseup(rct_window *w, rct_widgetindex widgetInde case WIDX_SECONDARY_PRICE:{ money32 price32 = (money32)window_ride_income_get_secondary_price(w); - money_to_string(price32, _moneyInputText, MONEY_STRING_MAXLENGTH); + money_to_string(price32, _moneyInputText, MONEY_STRING_MAXLENGTH, true); window_text_input_raw_open(w, WIDX_SECONDARY_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, _moneyInputText, MONEY_STRING_MAXLENGTH); }break; case WIDX_SECONDARY_PRICE_SAME_THROUGHOUT_PARK: diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index 23d387386d..db19b5d906 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -1336,7 +1336,7 @@ money32 string_to_money(const char* string_to_monetise) return result; } -void money_to_string(money32 amount, char * buffer_to_put_value_to, size_t buffer_len) +void money_to_string(money32 amount, char * buffer_to_put_value_to, size_t buffer_len, bool forceDecimals) { if (amount == MONEY32_UNDEFINED) { snprintf(buffer_to_put_value_to, buffer_len, "0"); @@ -1344,18 +1344,28 @@ void money_to_string(money32 amount, char * buffer_to_put_value_to, size_t buffe } int sign = amount >= 0 ? 1 : -1; int a = abs(amount); - if (a / 10 > 0 && a % 10 > 0) { // If whole and decimal exist + + bool amountIsInteger = (a / 10 > 0) && (a % 10 == 0); + + // If whole and decimal exist + if ((a / 10 > 0 && a % 10 > 0) || (amountIsInteger && forceDecimals)) + { const char* decimal_char = language_get_string(STR_LOCALE_DECIMAL_POINT); snprintf(buffer_to_put_value_to, buffer_len, "%d%s%d0", (a / 10) * sign, decimal_char, a % 10); } - else if (a / 10 > 0 && a % 10 == 0) { // If whole exists, but not decimal + // If whole exists, but not decimal + else if (amountIsInteger) + { snprintf(buffer_to_put_value_to, buffer_len, "%d", (a / 10) * sign); } - else if (a / 10 == 0 && a % 10 > 0) { // If decimal exists, but not whole + // If decimal exists, but not whole + else if (a / 10 == 0 && a % 10 > 0) + { const char* decimal_char = language_get_string(STR_LOCALE_DECIMAL_POINT); snprintf(buffer_to_put_value_to, buffer_len, "%s0%s%d0", sign < 0 ? "-" : "", decimal_char, a % 10); } - else { + else + { snprintf(buffer_to_put_value_to, buffer_len, "0"); } } diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index 70eb7adb48..63490b9a1e 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -43,7 +43,7 @@ sint32 get_string_length(const utf8 *text); // The maximum number of characters allowed for string/money conversions (anything above will risk integer overflow issues) #define MONEY_STRING_MAXLENGTH 14 money32 string_to_money(const char* string_to_monetise); -void money_to_string(money32 amount, char * buffer_to_put_value_to, size_t buffer_len); +void money_to_string(money32 amount, char * buffer_to_put_value_to, size_t buffer_len, bool forceDecimals); void user_string_clear_all(); rct_string_id user_string_allocate(sint32 base, const utf8 *text);