Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, May 2007
data type convertation


Message 1 in thread

Hi, all
It's about data type convertation in qt4.
for example:
double i;
double j;
I want to get j from i with 4 digits after dot (%.4f format as in c/c++).
that is , if i =0.000000 , I want j = 0.0000
Hope that I could be understood well.
Regards
Feng-li

Message 2 in thread

This is described in the documentation of Qt. Please see the documentation of QString on how to format your string, more specifically, take a look at the QString::number() function for doubles. You would be interested in the precision argument.

 

Regards,

Daniel Hedberg

 

________________________________

From: ååä [mailto:zhangfenglisdu@xxxxxxxxx] 
Sent: den 3 maj 2007 10:23
To: qt-interest
Subject: data type convertation

 

Hi, all
It's about data type convertation in qt4.
for example:
double i;
double j;
I want to get j from i with 4 digits after dot (%.4f format as in c/c++).
that is , if i =0.000000 , I want j = 0.0000 
Hope that I could be understood well.
Regards
Feng-li


Message 3 in thread

"???" <zhangfenglisdu@xxxxxxxxx> wrote in message 
news:340b09b40705030122g2a9e74cauf464f06e217e0d0d@xxxxxxxxxxxxxxxxx
> Hi, all
> It's about data type convertation in qt4.
> for example:
> double i;
> double j;
> I want to get j from i with 4 digits after dot (%.4f format as in 
> c/c++).
> that is , if i =0.000000 , I want j = 0.0000
> Hope that I could be understood well.
> Regards
> Feng-li
>


Hm, both i and j are doubles in your example... Since you quote %.4f I 
assume you are planning to make j a QString, in which case look at 
QString::sprintf and QString::arg.

http://doc.trolltech.com/4.2/qstring.html#arg-15
http://doc.trolltech.com/4.2/qstring.html#sprintf


Volkes


--
 [ signature omitted ]