Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-114343

QLocale::toDouble and QLocale::toFloat have different behaviours on various OS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 6.5.0
    • Core: Locales (i18n)
    • None
    • Linux: gcc x86_64
      Windows: MSVC 2019 / 2022 x64
    • Linux/X11, Linux/Other display system, Windows

    Description

      The example given in Qt docs https://doc.qt.io/qt-6/qlocale.html#toDouble does not work as expected and the result is different on different Linux computers / Windows.

      The following test does not work on our Linux build server but on my desktop Linux:

      QLocale::setDefault(QLocale(QLocale::German, QLocale::Germany));
      const QString englishFloat = "3.5";
      const QString germanFloat = "3,5";
      bool myOK = false;
      /* On my Linux desktop and the Linux build server: result = 3.5, ok = true
         On my windows desktop result = 0, ok = false */
      float result = QLocale::system().toFloat(englishFloat, &myOK);
      
      /* On my Linux desktop and windows desktop: result = 3.5, ok = true
         on my Linux build server result = 0, ok = false */
      result = QLocale::system().toFloat(germanFloat, &myOK);
      

      With Qt 5.15.2, QString::number() would give me for both strings the result 3.5 without setting any QLocale. That would be my desired result...

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Eddy Edward Welbourne
            davidweisgerber David Weisgerber
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes