String formatting for QString::number()
-
wrote on 23 Feb 2022, 07:39 last edited by
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 withCase-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?
-
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 withCase-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?
wrote on 23 Feb 2022, 10:10 last edited by JonB@Swati777999
I thinke
notation always puts in ane[+-]num
whilef
will only do so if the number is big or small? Did you try them to see?UPDATE
Sorry, I mixed upf
withg
format.f
format will not apparently ever usee[+-]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/2