如何将QString转换为十进制?
在C#代码中,它看起来像这样:
public static decimal ConvertToDecimal(string tekst, bool upperOnly) { decimal num = 0m; decimal num2 = 1m; string text = upperOnly ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234"; int i = tekst.Length - 1; while (i >= 0) { num += text.IndexOf(tekst[i]) * num2; i--; num2 *= text.Length; } return num; }
lpapp.. 6
根据文件:
int QString::toInt(bool * ok = 0, int base = 10) const
返回
string
转换为int
使用碱碱,这是10
通过缺省,如果转换失败必须在2到36,或0,则返回0之间.如果发生转换错误,
*ok
则设置为false; 否则*ok
设置为true.如果base为0,则使用C语言约定:如果字符串以"0x"开头,则使用base 16; 如果
string
以"0"开头,则使用基数8; 否则,使用基数10.字符串转换将始终在"C"语言环境中进行.用于依赖于语言环境的转换
QLocale::toInt()
例:
QString str = "FF"; bool ok; int hex = str.toInt(&ok, 16); // hex == 255, ok == true int dec = str.toInt(&ok, 10); // dec == 0, ok == false
请注意,根据您的确切用例,您可能还希望查看以下文档:
long QString::toLong(bool * ok = 0, int base = 10) const
qlonglong QString::toLongLong(bool * ok = 0, int base = 10) const
double QString::toDouble(bool * ok = 0) const
float QString::toFloat(bool * ok = 0) const
根据文件:
int QString::toInt(bool * ok = 0, int base = 10) const
返回
string
转换为int
使用碱碱,这是10
通过缺省,如果转换失败必须在2到36,或0,则返回0之间.如果发生转换错误,
*ok
则设置为false; 否则*ok
设置为true.如果base为0,则使用C语言约定:如果字符串以"0x"开头,则使用base 16; 如果
string
以"0"开头,则使用基数8; 否则,使用基数10.字符串转换将始终在"C"语言环境中进行.用于依赖于语言环境的转换
QLocale::toInt()
例:
QString str = "FF"; bool ok; int hex = str.toInt(&ok, 16); // hex == 255, ok == true int dec = str.toInt(&ok, 10); // dec == 0, ok == false
请注意,根据您的确切用例,您可能还希望查看以下文档:
long QString::toLong(bool * ok = 0, int base = 10) const
qlonglong QString::toLongLong(bool * ok = 0, int base = 10) const
double QString::toDouble(bool * ok = 0) const
float QString::toFloat(bool * ok = 0) const