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

Error formating number with locale es_ES

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.5.3, 6.6.2, 6.7.2
    • Core: Locales (i18n)
    • None
    • Windows
    • 287f3097f (dev)

    Description

      Using the locale es_ES (i.e. Spanish (Spain)). When converting numbers between 1000 and 9999 to a string, the thousands separator is not displayed. Numbers equal to or greater than 10000 if displayed correctly.

      The following code allows you to display this error:

      #include <QLocale>
      #include <iostream> 
      
      void testResult(double test, QString expected)
      {    
           QString result = QLocale::system().toString(test, 'f', 2);
           std::cout << result.toStdString();
           if (result == expected) {
              std::cout << " CORRECT" << std::endl;
          } else {
              std::cout << " WRONG! Must be " << expected.toStdString() << std::endl;
          }
      }
      
      int main(int argc, char *argv[])
      {
          setlocale(LC_ALL, "es_ES.UTF-8");
      
          std::cout << "Using Qt " << QT_VERSION_STR << std::endl;
          testResult(1111.11, "1.111,11");
          testResult(11111.11, "11.111,11");
          testResult(1111111.11, "1.111.111,11");
          testResult(11111111.11, "11.111.111,11");
      }
      

      Running this code in various Qt environments (5.14.2, 6.5.3 and 6.7.2) yields:

       

      Using Qt 6.7.2
      1111,11 WRONG! Must be 1.111,11
      11.111,11 CORRECT
      1.111.111,11 CORRECT 
      11.111.111,11 CORRECT 
      Using Qt 6.5.3
      1111,11 WRONG! Must be 1.111,11
      11.111,11 CORRECT 
      1.111.111,11 CORRECT 
      11.111.111,11 CORRECT
      
      Using Qt 5.14.2 
      1.111,11 CORRECT 
      11.111,11 CORRECT 
      1.111.111,11 CORRECT 
      11.111.111,11 CORRECT
      

      As you can see, only in Qt 5.14.2 the correct result is shown.

      Thanks, Jesús

       

       

      Attachments

        Issue Links

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

          Activity

            People

              Eddy Edward Welbourne
              jrleal Jesus Rodriguez Leal
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes