Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLocale::toCurrencyString(negative_number, Symbol) does not return correct value
QtWS25 Last Chance

QLocale::toCurrencyString(negative_number, Symbol) does not return correct value

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 428 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Melu
    wrote on last edited by
    #1

    Hi folks, I am woking on a codebase and was looking to migrate from qt5.12 to qt5.15. However I noticed that there is something off with QLocale::toCurrencyString returning wrong output on qt5.15.10 when I pass in a negative number. This affects a few Locals, I tested this with an imperfect program:

    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        double  amount = (-1001) / 1000.0;
        for(int i = QLocale::AnyLanguage; i<QLocale::Buginese; ++i){
            QLocale locale_(static_cast<QLocale::Language>(i));
    	QString currencySymbol = locale_.currencySymbol(QLocale::CurrencySymbol);
    	qDebug() << "Price is: " <<  locale_.toCurrencyString(amount, currencySymbol);
        }
        return a.exec();
    }
    

    Sample of the results are as below:

    Price is:  "Br-1.00"
    Price is:  "ETB -1.00"
    Price is:  "(R1,00)"
    Price is:  "(1 Lekë)"
    Price is:  "(ብር1.00)"
    Price is:  "-١٫٠٠ ج.م.\u200F"
    Price is:  "-1,00 ֏"
    Price is:  "₹ -১.০০"
    Price is:  "-£1.00"
    Price is:  "-1,00 ₼"
    Price is:  "₽ -1.00"
    Price is:  "(1,00 €)"
    Price is:  "(১.০০৳)"
    Price is:  "Nu.-༡.༠༠"
    Price is:  "-£1.00"
    Price is:  "-£1.00"
    Price is:  "-1,00 €"
    Price is:  "(1,00 лв.)"
    Price is:  "K -၁"
    Price is:  "-1,00 Br"
    Price is:  "(1,00៛)"
    Price is:  "(1,00 €)"
    Price is:  "(¥1.00)"
    Price is:  "€ -1.00"
    Price is:  "−1,00 HRK"
    Price is:  "-1,00 Kč"
    Price is:  "-1,00 kr."
    Price is:  "(€ 1,00)"
    Price is:  "($1.00)"
    Price is:  " −1,00"
    Price is:  "(1,00 €)"
    Price is:  "(1,00 kr)"
    Price is:  "-£1.00"
    Price is:  "−1,00 €"
    Price is:  "(1,00 €)"
    Price is:  "(€ 1,00)"
    Price is:  "(£1.00)"
    Price is:  "-1,00 €"
    Price is:  "-1,00 ₾"
    Price is:  "-1,00 €"
    Price is:  "-1,00 €"
    Price is:  "kr.−1,00"
    

    Is this the expected behaviour or is there something off? If it is the default behaviour is there a way to get the actual correct values with the correct signs and without the parenthesis like we had on qt5.12

    Christian EhrlicherC 1 Reply Last reply
    0
    • M Melu

      Hi folks, I am woking on a codebase and was looking to migrate from qt5.12 to qt5.15. However I noticed that there is something off with QLocale::toCurrencyString returning wrong output on qt5.15.10 when I pass in a negative number. This affects a few Locals, I tested this with an imperfect program:

      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          double  amount = (-1001) / 1000.0;
          for(int i = QLocale::AnyLanguage; i<QLocale::Buginese; ++i){
              QLocale locale_(static_cast<QLocale::Language>(i));
      	QString currencySymbol = locale_.currencySymbol(QLocale::CurrencySymbol);
      	qDebug() << "Price is: " <<  locale_.toCurrencyString(amount, currencySymbol);
          }
          return a.exec();
      }
      

      Sample of the results are as below:

      Price is:  "Br-1.00"
      Price is:  "ETB -1.00"
      Price is:  "(R1,00)"
      Price is:  "(1 Lekë)"
      Price is:  "(ብር1.00)"
      Price is:  "-١٫٠٠ ج.م.\u200F"
      Price is:  "-1,00 ֏"
      Price is:  "₹ -১.০০"
      Price is:  "-£1.00"
      Price is:  "-1,00 ₼"
      Price is:  "₽ -1.00"
      Price is:  "(1,00 €)"
      Price is:  "(১.০০৳)"
      Price is:  "Nu.-༡.༠༠"
      Price is:  "-£1.00"
      Price is:  "-£1.00"
      Price is:  "-1,00 €"
      Price is:  "(1,00 лв.)"
      Price is:  "K -၁"
      Price is:  "-1,00 Br"
      Price is:  "(1,00៛)"
      Price is:  "(1,00 €)"
      Price is:  "(¥1.00)"
      Price is:  "€ -1.00"
      Price is:  "−1,00 HRK"
      Price is:  "-1,00 Kč"
      Price is:  "-1,00 kr."
      Price is:  "(€ 1,00)"
      Price is:  "($1.00)"
      Price is:  " −1,00"
      Price is:  "(1,00 €)"
      Price is:  "(1,00 kr)"
      Price is:  "-£1.00"
      Price is:  "−1,00 €"
      Price is:  "(1,00 €)"
      Price is:  "(€ 1,00)"
      Price is:  "(£1.00)"
      Price is:  "-1,00 €"
      Price is:  "-1,00 ₾"
      Price is:  "-1,00 €"
      Price is:  "-1,00 €"
      Price is:  "kr.−1,00"
      

      Is this the expected behaviour or is there something off? If it is the default behaviour is there a way to get the actual correct values with the correct signs and without the parenthesis like we had on qt5.12

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Melu said in QLocale::toCurrencyString(negative_number, Symbol) does not return correct value:

      qt5.15.10

      Since this is a commercial-only version you should ask the Qt support.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Melu said in QLocale::toCurrencyString(negative_number, Symbol) does not return correct value:

        qt5.15.10

        Since this is a commercial-only version you should ask the Qt support.

        M Offline
        M Offline
        Melu
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thanks for the response. I will do so. I wanted to note that the same issue is on the open source version 5.15.5 downloaded from: https://download.qt.io/official_releases/qt/5.15/5.15.5/single.

        1 Reply Last reply
        0
        • kkoehneK Offline
          kkoehneK Offline
          kkoehne
          Moderators
          wrote on last edited by
          #4

          @Melu said in QLocale::toCurrencyString(negative_number, Symbol) does not return correct value:

          [..] However I noticed that there is something off with QLocale::toCurrencyString returning wrong output on qt5.15.10 when I pass in a negative number.

          I think this is behavior described in https://bugreports.qt.io/browse/QTBUG-89383 . So it seems the parenthesis are used in 'accounting format' for some locales.

          Director R&D, The Qt Company

          M 1 Reply Last reply
          1
          • kkoehneK kkoehne

            @Melu said in QLocale::toCurrencyString(negative_number, Symbol) does not return correct value:

            [..] However I noticed that there is something off with QLocale::toCurrencyString returning wrong output on qt5.15.10 when I pass in a negative number.

            I think this is behavior described in https://bugreports.qt.io/browse/QTBUG-89383 . So it seems the parenthesis are used in 'accounting format' for some locales.

            M Offline
            M Offline
            Melu
            wrote on last edited by
            #5

            @kkoehne thanks for pointing me to this.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved