mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Refactor float conversion in CommonCLI to use strtof for improved precision and add ftoa3 function for formatting floats with three decimal places in TxtDataHelpers to fix display issue in app and repeater config ui in web
REPO: 1. Flash a repeater 2. Connect over lora 3. Set bw to 42.7 KHZ It will revert back due to converting a double to a float. REPO2: 1.Flash Repeater 2. Apply float fix 3. Set to say 20.8 4. try to get value via app or web cli repeater config It wil show blank because it doesnt return a good value. It would be something like 20.7999992 which the app and web apps dont like so the ftoa3 rounds it and returns a 3 decimal point float
This commit is contained in:
parent
8dbb0f5f23
commit
850d57a8f2
3 changed files with 19 additions and 5 deletions
|
|
@ -140,6 +140,19 @@ const char* StrHelper::ftoa(float f) {
|
|||
return tmp;
|
||||
}
|
||||
|
||||
const char* StrHelper::ftoa3(float f) {
|
||||
static char s[16];
|
||||
int v = (int)(f * 1000.0f + (f >= 0 ? 0.5f : -0.5f)); // rounded ×1000
|
||||
int w = v / 1000; // whole
|
||||
int d = abs(v % 1000); // decimals
|
||||
snprintf(s, sizeof(s), "%d.%03d", w, d);
|
||||
for (int i = strlen(s) - 1; i > 0 && s[i] == '0'; i--)
|
||||
s[i] = 0;
|
||||
int L = strlen(s);
|
||||
if (s[L - 1] == '.') s[L - 1] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t StrHelper::fromHex(const char* src) {
|
||||
uint32_t n = 0;
|
||||
while (*src) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue