title: Converting number to currency string using QLocale class
body: <p>I am trying to convert numbers into currency string. I am using <code>QLocale::toCurrencyString()</code> method. 
  When I set my system locale(changed via Windows 7 Region and Language setup) as India and try to convert a number say <code>1872345.00</code> using <code>QLocale().toCurrencyString(1872345.00)</code>, I get the expected currency string. </p>
  
  <p><img src="https://i.stack.imgur.com/UexlS.png" alt="QLocale().toCurrencyString(1872345.00)"></p>
  
  <p>But when I call <code>QLocale(QLocale::AnyLanguage,QLocale::AnyScript,QLocale::India).toCurrencyString(1872345.00);</code>, I get the number formatted like this which is not correct.</p>
  
  <p><img src="https://i.stack.imgur.com/NE9dC.png" alt="QLocale(QLocale::AnyLanguage,QLocale::AnyScript,QLocale::India).toCurrencyString(1872345.00)"></p>
  
  <p>I tried choosing different locale Scripts and locale Languages. But I was not able to get the right result. I am using Qt 5.1.0. Though I am getting right results when I use <code>QLocale().toCurrencyString()</code>  I cannot use it because I am dealing with currencies of multiple countries and not just the country as set by system locale. Why is that I am getting this incorrect result? How do I convert numbers to currency string (of different countries)?    </p>
  
  <p>Here's an example code.</p>
  
  <p>//CurrencyForms.h</p>
  
  <pre><code>#ifndef CURRENCYFORMS_H
  #define CURRENCYFORMS_H
  
  #include &lt;QObject&gt;
  
  class CurrencyForms : public QObject
  {
      Q_OBJECT
      Q_PROPERTY(QString defaultLocaleString READ defaultLocaleString CONSTANT)
      Q_PROPERTY(QString constructedLocaleStringAnyLanguage READ constructedLocaleStringAnyLanguage CONSTANT)
      Q_PROPERTY(QString constructedLocaleStringHindiLanguage READ constructedLocaleStringHindiLanguage CONSTANT)
  public:
      explicit CurrencyForms(QObject *parent = 0);
      QString defaultLocaleString();
      QString constructedLocaleStringAnyLanguage();
      QString constructedLocaleStringHindiLanguage();
  };
  
  #endif // CURRENCYFORMS_H
  </code></pre>
  
  <p>//CurrencyForms.cpp</p>
  
  <pre><code>#include "CurrencyForms.h"
  #include&lt;QLocale&gt;
  CurrencyForms::CurrencyForms(QObject *parent) :
      QObject(parent)
  {
  }
  
  QString CurrencyForms::defaultLocaleString()
  {
      return QLocale().toCurrencyString(1872345.00);
  }
  
  QString CurrencyForms::constructedLocaleStringAnyLanguage()
  {
      return QLocale(QLocale::AnyLanguage,QLocale::AnyScript,QLocale::India).toCurrencyString(1872345.00);
  }
  
  QString CurrencyForms::constructedLocaleStringHindiLanguage()
  {
      return  QLocale(QLocale::Hindi,QLocale::AnyScript,QLocale::India).toCurrencyString(1872345.00);
  }
  </code></pre>
  
  <p>//main.cpp</p>
  
  <pre><code>#include &lt;QtGui/QGuiApplication&gt;
  #include "qtquick2applicationviewer.h"
  #include &lt;QQmlContext&gt;
  #include &lt;CurrencyForms.h&gt;
  int main(int argc, char *argv[])
  {
      QGuiApplication app(argc, argv);
  
      QtQuick2ApplicationViewer viewer;
      CurrencyForms forms;
      viewer.rootContext()-&gt;setContextProperty("forms",&amp;forms);
      viewer.setMainQmlFile(QStringLiteral("qml/CurrencySymbolTest/main.qml"));
      viewer.showExpanded();
  
      return app.exec();
  }
  </code></pre>
  
  <p>//main.qml</p>
  
  <pre><code>import QtQuick 2.0
  
  Rectangle {
      width: 720
      height: 360
      Grid{
          columns:1
          spacing:2
          width: parent.width
          Text{
              id:defaultLocaleText
              width:parent.width
              height:60
              font.pixelSize:14
              elide:Text.ElideRight
              text:"QLocale().toCurrencyString(1872345.00)"
              verticalAlignment: Text.AlignVCenter
          }
          Text{
              id:defaultLocaleTextResult
              width:parent.width
              height:60
              font.pixelSize:40
              elide:Text.ElideRight
              text:forms.defaultLocaleString
              verticalAlignment: Text.AlignVCenter
              color:"green"
          }
          Text{
              id:constructedLocaleStringAnyLanguageText
              width:parent.width
              height:60
              font.pixelSize:14
              elide:Text.ElideRight
              text:"QLocale(QLocale::AnyLanguage,QLocale::AnyScript,QLocale::India).toCurrencyString(1872345.00)"
              verticalAlignment: Text.AlignVCenter
          }
          Text{
              id:constructedLocaleStringAnyResult
              width:parent.width
              height:60
              font.pixelSize:40
              elide:Text.ElideRight
              text:forms.constructedLocaleStringAnyLanguage
              verticalAlignment: Text.AlignVCenter
              color:"red"
          }
          Text{
              id:constructedLocaleStringHindiLanguage
              width:parent.width
              height:60
              font.pixelSize:14
              elide:Text.ElideRight
              text:"QLocale(QLocale::Hindi,QLocale::AnyScript,QLocale::India).toCurrencyString(1872345.00)"
              verticalAlignment: Text.AlignVCenter
          }
          Text{
              id:constructedLocaleStringHindiLanguageResult
              width:parent.width
              height:60
              font.pixelSize:40
              elide:Text.ElideRight
              text:forms.constructedLocaleStringHindiLanguage
              verticalAlignment: Text.AlignVCenter
              color:"red"
          }
  
      }
  
  }
  </code></pre>
  
  <p>//Result
  <img src="https://i.stack.imgur.com/mg7v4.png" alt="enter image description here"></p>
  
  <p>here my default system locale is set as Hindi India (via Windows 7 Region and Language setup)</p>