Fix sprint_freq to show appropriate # of decimal places to get to 0.1Hz on all scales

pull/668/head
Mike Black W9MDB 2021-04-15 12:24:29 -05:00
rodzic 7d79b59bd7
commit a1f5d4f5e3
1 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

@ -351,6 +351,7 @@ int HAMLIB_API sprintf_freq(char *str, int nlen, freq_t freq)
{
double f;
char *hz;
int decplaces = 10;
// too verbose
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
@ -364,19 +365,22 @@ int HAMLIB_API sprintf_freq(char *str, int nlen, freq_t freq)
{
hz = "MHz";
f = (double)freq / MHz(1);
decplaces = 7;
}
else if (llabs(freq) >= kHz(1))
{
hz = "kHz";
f = (double)freq / kHz(1);
decplaces = 4;
}
else
{
hz = "Hz";
f = (double)freq;
decplaces = 1;
}
return sprintf(str, "%g %s", f, hz);
return sprintf(str, "%.*f %s", decplaces , f, hz);
}