I`m using double everywhere. Lemme try your code and i`ll be back.
Edit:
str << "100000.55" << "10000.55" << "1000.55";
printf("%f\n", s.toDouble());
qDebug() << "qDebug: " << s.toDouble();
}
QStringList str;
str << "100000.55" << "10000.55" << "1000.55";
foreach(const QString &s, str){
printf("%f\n", s.toDouble());
qDebug() << "qDebug: " << s.toDouble();
}
To copy to clipboard, switch view to plain text mode
This code gives me the next results:
100000.550000
qDebug: 100001
10000.550000
qDebug: 10000.5
1000.550000
qDebug: 1000.55
Why is that rounding and any idea [in code] how to get the real precise value from the database without the rounding?
Edit2: Or should i have to use sprintf(), atof() or something like that so i can get the precise value into a double? That`s too... complicated.
Edit3: wysota, try to put a bigger number with 2 digits after the floating point like 100000.55 and in the second example u gave me it will round the bigger number. It will make it 100001.. thats 0.45 cents gain per calculation. Not good
no precise
Edit4:
while (query.next()) {
eur = query.value(1).toByteArray();
}
//eur == 100000.55
char *euC = eu.data();
double euDbl = atof(euC);
qDebug() << euC << euDbl;
//result is: 100000.55 100001
QByteArray eur;
while (query.next()) {
eur = query.value(1).toByteArray();
}
//eur == 100000.55
char *euC = eu.data();
double euDbl = atof(euC);
qDebug() << euC << euDbl;
//result is: 100000.55 100001
To copy to clipboard, switch view to plain text mode
What is wrong here... 5 digits numbers get rounded 1 digit after the point, 6 digits numbers get rounded to an integer. OR nothing is wrong and i`m in the biggest math mistake in my life lol 
100000.55 goes 100001
10000.55 goes 10000.5
1000.55 goes 1000.55
That rounding happens when converting from database result to number (double)
Is it normal? Or using floats or doubles with currencies is a no no.
Bookmarks