开发者

Displaying decimal values in Qt using qreal Data Type

Is there a way to get decimal values using qreal in Qt??

just like this:

qreal decimal;
average = 3/2;

the output should definitely 1.5 but instead i am getting 1 as result.

can anyone 开发者_Python百科help me??


Because everybody is saying how to solve the problem and not what is the problem, here is my answer:

Operations on integers returns integers. To get a real number you should cast one of the operands to a real type.


@andro, you could do (x*1.0)/y or (qreal)x/y


qreal average;
average = 3.0/2;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜