| @@ -14,10 +14,23 @@ std::string Quantity::getDisplayValueString() { | |||||
| } | } | ||||
| void Quantity::setDisplayValueString(std::string s) { | void Quantity::setDisplayValueString(std::string s) { | ||||
| float displayValue = 0.f; | |||||
| int n = std::sscanf(s.c_str(), "%f", &displayValue); | |||||
| if (n == 1) | |||||
| setDisplayValue(displayValue); | |||||
| float v = 0.f; | |||||
| char suffix[2]; | |||||
| int n = std::sscanf(s.c_str(), "%f%1s", &v, suffix); | |||||
| if (n >= 2) { | |||||
| // Parse SI prefixes | |||||
| switch (suffix[0]) { | |||||
| case 'n': v *= 1e-9f; break; | |||||
| case 'u': v *= 1e-6f; break; | |||||
| case 'm': v *= 1e-3f; break; | |||||
| case 'k': v *= 1e3f; break; | |||||
| case 'M': v *= 1e6f; break; | |||||
| case 'G': v *= 1e9f; break; | |||||
| default: break; | |||||
| } | |||||
| } | |||||
| if (n >= 1) | |||||
| setDisplayValue(v); | |||||
| } | } | ||||
| std::string Quantity::getString() { | std::string Quantity::getString() { | ||||