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 ignores precision
Forum Updated to NodeBB v4.3 + New Features

QLocale toCurrencyString ignores precision

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 713 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.
  • J Offline
    J Offline
    JBES
    wrote on last edited by
    #1

    Hi,

    (QT 5.10.1 MSVC 2015 32 bit)

    I'm not sure if I'm missing something here, but the results I get using the toCurrencyString overload with a double and precision completely ignore the precision that is set.

    E.g. With the example below, from a double of 1234567.12 the result I would expect is €1,234,567 but the result I actually get (€1,234,567.12) always has a precision of 2.

    QString szCurSym = QLocale("es_ES").currencySymbol();
    double dblTestVal=1234567.12;
    QString szResult=QLocale().toCurrencyString(dblTestVal,szCurSym,0); //precision ignored
    

    Thanks in advance.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      That's because you are using the system locale (i.e. QLocale()) it is documented even if a bit obscure:
      http://doc.qt.io/qt-5/qlocale.html#system

      On Windows and Mac, this locale will use the decimal[...] formats specified in the system configuration panel.

      QLocale(QLocale().language(),QLocale().country()).toCurrencyString(dblTestVal,szCurSym,0); will actually use the precision

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • J Offline
        J Offline
        JBES
        wrote on last edited by
        #3

        @VRonin said in QLocale toCurrencyString ignores precision:

        QLocale(QLocale().language(),QLocale().country()).toCurrencyString(dblTestVal,szCurSym,0);

        Thanks, that works. You would think that specifically setting the precision would take precedence. Maybe it would be better worded as ... the locale will always use ...

        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