Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Showing numbers in decimal not scientific notation
Forum Updated to NodeBB v4.3 + New Features

Showing numbers in decimal not scientific notation

Scheduled Pinned Locked Moved Unsolved General and Desktop
41 Posts 9 Posters 31.4k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J.HilkJ J.Hilk

    Hi,

    for your specific situation, I would suggest something like:

    QString truncValue(double value, int prec)
    {
        QString sReturn = QString::number(value,'f',prec);
        if(sReturn.endsWith("0")){
            while(sReturn.endsWith("0"))
                sReturn.remove(sReturn.length()-1,1);
    
            if(sReturn.endsWith("."))
                sReturn.remove(sReturn.length()-1,1);
        }
        
        return sReturn;
    }
    

    But, this is successively chaining a lot of string operations. The previously mentions methods are probably better.

    tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by
    #41

    @J.Hilk
    Thank you for the code.
    honestly, I solved the issue two or three days ago. When I found I can't rely on a function offered by Qt on this specific problem, I returned to my old friend, C++, and solved the issue using it.
    But I appreciate your paying attention to the problem.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved