Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
how to convert double number to quint16
ThenewQtDev last edited by kshegunov
i have quint number multiply to 3.6067688
and i want to get the quint result
i know it is easy but really it took time from me
and i couldnt solve it
[Moved to the proper forum ~kshegunov]
double x = 3.6; quint32 l = quint32(x + 0.5);
6thC last edited by
I'm sure you guys know what you are doing, I just always get red flags and start to questioning / confirming I do mean to use unsigned - Just thinking aloud about potentials:
1: using quint32 = unsigned int; 2: x= std::numeric_limits<unsigned int>::max(); 3: x + 0.5 4: ?lost profit?
If you want to handle the overflow you need to handle it manually anyway. There's no way to signal that a conversion has failed by the result itself, so the be completely proper you'd need to check if the double you're converting from is over the max value of the resulting type minus 0.5 and if so you're going to overflow.