Fix rounding bug when displaying frequencies (#1801)

This commit is contained in:
Mark Thompson 2024-01-22 00:54:29 -06:00 committed by GitHub
parent ac1d350aaf
commit 0f85f247b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 4 deletions

View File

@ -185,7 +185,7 @@ std::string to_string_freq(const uint64_t f) {
// right-justified frequency in MHz, rounded to 4 decimal places, always 9 characters // right-justified frequency in MHz, rounded to 4 decimal places, always 9 characters
std::string to_string_short_freq(const uint64_t f) { std::string to_string_short_freq(const uint64_t f) {
auto final_str = to_string_dec_int(f / 1000000, 4) + "." + to_string_dec_int(((f + 50) / 100) % 10000, 4, '0'); auto final_str = to_string_dec_int((f + 50) / 1000000, 4) + "." + to_string_dec_int(((f + 50) / 100) % 10000, 4, '0');
return final_str; return final_str;
} }
@ -210,7 +210,7 @@ std::string to_string_rounded_freq(const uint64_t f, int8_t precision) {
uint32_t divisor = pow10[6 - precision]; uint32_t divisor = pow10[6 - precision];
final_str = to_string_dec_uint(f / 1000000) + "." + to_string_dec_int(((f + (divisor / 2)) / divisor) % pow10[precision], precision, '0'); final_str = to_string_dec_uint((f + (divisor / 2)) / 1000000) + "." + to_string_dec_int(((f + (divisor / 2)) / divisor) % pow10[precision], precision, '0');
} }
return final_str; return final_str;
} }

View File

@ -85,7 +85,7 @@ const tone_key_t tone_keys = {
{"Senn. 32.768k", F2Ix100(32768.0)}}; {"Senn. 32.768k", F2Ix100(32768.0)}};
std::string fx100_string(uint32_t f) { std::string fx100_string(uint32_t f) {
return to_string_dec_uint(f / 100) + "." + to_string_dec_uint(((f + 5) / 10) % 10); return to_string_dec_uint((f + 5) / 100) + "." + to_string_dec_uint(((f + 5) / 10) % 10);
} }
float tone_key_frequency(tone_index index) { float tone_key_frequency(tone_index index) {

View File

@ -498,12 +498,13 @@ void GeoMap::draw_scale(Painter& painter) {
if (m < 1000) { if (m < 1000) {
km_string = to_string_dec_uint(m) + "m"; km_string = to_string_dec_uint(m) + "m";
} else { } else {
m += 50; // (add rounding factor for div by 100 below)
uint32_t km = m / 1000; uint32_t km = m / 1000;
m -= km * 1000; m -= km * 1000;
if (m == 0) { if (m == 0) {
km_string = to_string_dec_uint(km) + " km"; km_string = to_string_dec_uint(km) + " km";
} else { } else {
km_string = to_string_dec_uint(km) + "." + to_string_dec_uint((m + 50) / 100, 1) + "km"; km_string = to_string_dec_uint(km) + "." + to_string_dec_uint(m / 100, 1) + "km";
} }
} }