How to convert float64 to QString



  • Hello Everyone,

    How i can convert float64 to QString. I am getting a variable value from a function with float64 type and i want to display it in QTextEdit. How I can do it. Thanks in advance.



  • QString floatToString = textEdit->locale().toString(floatValue,'f');



  • @VRonin
    I want to dsiplay it in QTextedit, dont want to set the value tof textedit to QString
    for example
    float64 value = 2.33

    QTextEdit *textbox = new QTextEdit;
    textbox->setText(value)


  • Moderators

    @rockon209

    QString floatToString = QLocale::system().toString(floatValue,'f');
    textbox->setText(floatToString);
    


  • @VRonin I am getting the following error
    error: no matching function for call to 'QLocale::toString(float64 [1], char)'
    QString floatToString = QLocale::system().toString(data1,'f');


  • Moderators

    @rockon209 Why do you use float64 instead of float or double?
    If you want to use float 64 then cast it to float or double first.
    And toString isn't a static method - you need a QLocale instance to use it.



  • If you mean float64 is equal to double, I would use the static function QString::number.

    double value = 1.234567:
    QString num = QString::number(value);
    


  • @jsulm @beecksche
    I am getting the value from a function and that function gives float64 value as return. I thought about that but dont know how to cast float64 to float. If you know it please let me know.


  • Moderators

    @rockon209

    double temp = static_cast<double>(value);
    

    use double to make sure it can represent all values a float64 can.



  • This post is deleted!


  • @rockon209 said in How to convert float64 to QString:

    @VRonin
    I want to dsiplay it in QTextedit, dont want to set the value tof textedit to QString

    That's not what I'm doing there

    you can even combine.textEdit->setText(textEdit->locale().toString(floatValue,'f'));


Log in to reply