本文整理汇总了C++中QLocale::exponential方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::exponential方法的具体用法?C++ QLocale::exponential怎么用?C++ QLocale::exponential使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocale
的用法示例。
在下文中一共展示了QLocale::exponential方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stringToValue
/// \brief Converts string containing value and (prefix+)unit to double (Counterpart to Helper::valueToString).
/// \param text The text containing the value and its unit.
/// \param unit The base unit of the value.
/// \param ok Pointer to a success-flag, true on success, false on error.
/// \return Decoded value.
double stringToValue(const QString &text, Unit unit, bool *ok) {
// Check if the text is empty
int totalSize = text.size();
if(!totalSize){
if(ok)
*ok = false;
return 0.0;
}
// Split value and unit apart
int valueSize = 0;
QLocale locale;
bool decimalFound = false;
bool exponentFound = false;
if(text[valueSize] == locale.negativeSign())
++valueSize;
for(; valueSize < text.size(); ++valueSize) {
QChar character = text[valueSize];
if(character.isDigit()) {
}
else if(character == locale.decimalPoint() && decimalFound == false && exponentFound == false) {
decimalFound = true;
}
else if(character == locale.exponential() && exponentFound == false) {
exponentFound = true;
if(text[valueSize + 1] == locale.negativeSign())
++valueSize;
}
else {
break;
}
}
QString valueString = text.left(valueSize);
bool valueOk = false;
double value = valueString.toDouble(&valueOk);
if(!valueOk) {
if(ok)
*ok = false;
return value;
}
QString unitString = text.right(text.size() - valueSize).trimmed();
if(ok)
*ok = true;
switch(unit) {
case UNIT_VOLTS: {
// Voltage string decoding
if(unitString.startsWith('\265'))
return value * 1e-6;
else if(unitString.startsWith('m'))
return value * 1e-3;
else
return value;
}
case UNIT_DECIBEL:
// Power level string decoding
return value;
case UNIT_SECONDS:
// Time string decoding
if(unitString.startsWith('p'))
return value * 1e-12;
else if(unitString.startsWith('n'))
return value * 1e-9;
else if(unitString.startsWith('\265'))
return value * 1e-6;
else if(unitString.startsWith("min"))
return value * 60;
else if(unitString.startsWith('m'))
return value * 1e-3;
else if(unitString.startsWith('h'))
return value * 3600;
else
return value;
case UNIT_HERTZ:
// Frequency string decoding
if(unitString.startsWith('k'))
return value * 1e3;
else if(unitString.startsWith('M'))
return value * 1e6;
else if(unitString.startsWith('G'))
return value * 1e9;
else
return value;
case UNIT_SAMPLES:
// Sample count string decoding
if(unitString.startsWith('k'))
return value * 1e3;
else if(unitString.startsWith('M'))
return value * 1e6;
else if(unitString.startsWith('G'))
return value * 1e9;
//.........这里部分代码省略.........