MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / FMT_VAL

Function FMT_VAL

app/src/UI/Dashboard.h:481–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479} // namespace UI
480
481inline QString FMT_VAL(double val, double min, double max)
482{
483 auto decPoints = [](double v) {
484 double abs = std::abs(v);
485 if (DSP::isZero(abs))
486 return 2;
487
488 if (abs >= 1e6)
489 return 0;
490
491 if (abs >= 1e5)
492 return 0;
493
494 if (abs >= 1e4)
495 return 0;
496
497 if (abs >= 1e3)
498 return 1;
499
500 if (abs >= 1e2)
501 return 2;
502
503 if (abs >= 1e1)
504 return 2;
505
506 if (abs >= 1.0)
507 return 3;
508
509 if (abs >= 1e-1)
510 return 4;
511
512 if (abs >= 1e-2)
513 return 5;
514
515 if (abs >= 1e-3)
516 return 6;
517
518 if (abs >= 1e-4)
519 return 7;
520
521 if (abs >= 1e-5)
522 return 8;
523
524 if (abs >= 1e-6)
525 return 9;
526
527 return 10;
528 };
529
530 if (DSP::isZero(min) && DSP::isZero(max))
531 return QString::number(val, 'f', decPoints(val));
532
533 else {
534 const int p = std::max(decPoints(min), decPoints(max));
535 return QString::number(val, 'f', p);
536 }
537}
538

Callers 2

formatValueMethod · 0.85
formatValueMethod · 0.85

Calls 2

absFunction · 0.85
isZeroFunction · 0.85

Tested by

no test coverage detected