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. String formatting for QString::number()
Forum Updated to NodeBB v4.3 + New Features

String formatting for QString::number()

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 7.4k Views
  • 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.
  • S Offline
    S Offline
    Swati777999
    wrote on 23 Feb 2022, 07:39 last edited by
    #1

    Hi All,

    I want to convert a float value to scientific notation [with 3 decimal places ]for example 8.3562456 = 83562.456e-4
    Can it be possible with

    Case-1:

    double num = 8.3562456 ;// user input
    int deci_pl = 3 ;// user input
    QString fin_val = QString::number(num,'e',deci_pl); 
    

    Case-2:

    double num=8.3562456 ;// user input
    int deci_pl = 3 ;// user input
    QString fin_val = QString::number(num,'f',deci_pl); 
    

    Which one of the two methods, will you suggest for this conversion?

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    J 1 Reply Last reply 23 Feb 2022, 10:10
    0
    • S Swati777999
      23 Feb 2022, 07:39

      Hi All,

      I want to convert a float value to scientific notation [with 3 decimal places ]for example 8.3562456 = 83562.456e-4
      Can it be possible with

      Case-1:

      double num = 8.3562456 ;// user input
      int deci_pl = 3 ;// user input
      QString fin_val = QString::number(num,'e',deci_pl); 
      

      Case-2:

      double num=8.3562456 ;// user input
      int deci_pl = 3 ;// user input
      QString fin_val = QString::number(num,'f',deci_pl); 
      

      Which one of the two methods, will you suggest for this conversion?

      J Offline
      J Offline
      JonB
      wrote on 23 Feb 2022, 10:10 last edited by JonB
      #2

      @Swati777999
      I think e notation always puts in an e[+-]num while f will only do so if the number is big or small? Did you try them to see?

      UPDATE
      Sorry, I mixed up f with g format. f format will not apparently ever use e[+-]num format. The various formats and their output are listed at https://doc.qt.io/qt-5/qstring.html#argument-formats, and you can try them out, so why not do so?

      1 Reply Last reply
      0

      1/2

      23 Feb 2022, 07:39

      • Login

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