Common: refactors number formatting to use type-specific append functions

This commit is contained in:
李通洲
2025-08-19 17:22:11 +08:00
parent 7f48500cfd
commit ec0fa89cc8
4 changed files with 29 additions and 11 deletions
+11 -3
View File
@@ -6,12 +6,20 @@ bool ffFreqAppendNum(uint32_t mhz, FFstrbuf* result)
return false;
const FFOptionsDisplay* options = &instance.config.display;
const char* space = options->freqSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_NEVER ? "" : " ";
bool spaceBeforeUnit = options->freqSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER;
int8_t ndigits = options->freqNdigits;
if (ndigits >= 0)
ffStrbufAppendF(result, "%.*f%sGHz", ndigits, mhz / 1000., space);
{
ffStrbufAppendDouble(result, mhz / 1000., ndigits);
if (spaceBeforeUnit) ffStrbufAppendC(result, ' ');
ffStrbufAppendS(result, "GHz");
}
else
ffStrbufAppendF(result, "%u%sMHz", (unsigned) mhz, space);
{
ffStrbufAppendUInt(result, mhz);
if (spaceBeforeUnit) ffStrbufAppendC(result, ' ');
ffStrbufAppendS(result, "MHz");
}
return true;
}