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

The QLocale::C should not have a separator for thousands in numerical values

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.6.0 Beta
    • 4.5.1, 5.5.0
    • Core: Locales (i18n)
    • None

    Description

      The C locale does not have a separator for thousands:

      #include <locale.h>
      #include <stdio.h>
      
      int main(int argc, char *argv[]){
        setlocale(LC_ALL,"C");
        struct lconv *cconv = localeconv();
        printf("%s\n", cconv->thousands_sep);
        printf("%s\n", cconv->mon_thousands_sep);
        return 0;
      }
      

      The locale QLocale::C has a coma has separator.
      Here is a test case for this:

      #include <QtTest/QtTest>
      #include <QLocale>
      
      class Test : public QObject{
        Q_OBJECT
      
      private slots:
        void testCLocaleThousandSeparator(){
          QCOMPARE(QLocale::c().toString(1000.0), QString::fromLatin1("1000"));
        }
        
      };
      
      QTEST_MAIN(Test)
      #include "test.moc"
      

      Here is a patch for this issue:

      diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
      index e670ad2..20c789b 100644
      --- a/src/corelib/tools/qlocale.cpp
      +++ b/src/corelib/tools/qlocale.cpp
      @@ -2233,7 +2233,7 @@ QLocale::QLocale(Language language, Country country)
               p.numberOptions = default_number_options;
               p.index = localePrivateIndex(defaultPrivate());
           } else {
      -        p.numberOptions = 0;
      +        p.numberOptions = QLocale::OmitGroupSeparator;
               p.index = localePrivateIndex(d);
           }
       }
      

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes