Results 1 to 3 of 3

Thread: Retrieve full decimal value from MySql database?

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Retrieve full decimal value from MySql database?

    When I retrieve decimal data from MySql if the value is Example: 10.00 it retrieves 10.
    I retrieve the data using:
    Qt Code:
    1. while(query.next()){
    2. QString number=query.value("decimalColumn").toSomething(); //tried toString(),toDouble(),toFloat() and all are retrieving the same
    3. }
    To copy to clipboard, switch view to plain text mode 
    How can I setup so I retrieve full decimal value even if its *.00 ?

    I can change fairly easy if the number appears like 99, but I get numbers like 99.90, so it if I append .00 there will be the issue of numbers appearing like 99.90.00.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Retrieve full decimal value from MySql database?

    Convert the query value to float and use QString::number (double n, char format, int precision) method to convert it to string (see argument formats).
    In your case QString::number(value,'f',2) should be ok
    Qt Code:
    1. while(query.next()){
    2. const float v = query.value("decimalColumn").toFloat();
    3. const QString number = QString::number(v,'f',2);
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to stampede for this useful post:

    adutzu89 (8th March 2014)

  4. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Retrieve full decimal value from MySql database?

    Thank you for your help.

Similar Threads

  1. Qt and MySQL database
    By Stanfillirenfro in forum Qt Programming
    Replies: 0
    Last Post: 26th June 2013, 07:58
  2. Sql query to retrieve database table data
    By Cyrebo in forum Qt Programming
    Replies: 9
    Last Post: 30th March 2013, 18:20
  3. Replies: 2
    Last Post: 14th September 2009, 08:38
  4. Replies: 2
    Last Post: 14th September 2009, 08:31
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 12:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.