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. Qt has No Decimal or Currency implement?
Forum Updated to NodeBB v4.3 + New Features

Qt has No Decimal or Currency implement?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 6 Posters 8.3k Views 2 Watching
  • 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.
  • R Offline
    R Offline
    rex0y
    wrote on last edited by
    #1

    I want to migret code from old applition.but a formula in OLD code using Decimal type calculate area,how can i replace Decimal type in Qt environment?
    or i think it is nessary to suport Decimal type in Qt 5.2!!!

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      C++ has the float and double types.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rex0y
        wrote on last edited by
        #3

        JKSH, are you really what is Decimal or Currency type ???????

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          I thought you meant something like "$29.95". That can be stored as a float.

          If that is not what you want, can you please give me an example of your Decimal/Currency type?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbzhang800
            wrote on last edited by
            #5

            Hi, if your code is written in C++ and Decimal is class of pure C++, you can use it in your Qt project directly. otherwise, you can use other 3rd party c++ decimal libraries

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dbzhang800
              wrote on last edited by
              #6

              FYI, https://code.google.com/p/qdecimal/

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                [quote author="rex0y" date="1390196104"]JKSH, are you really what is Decimal or Currency type ???????[/quote]I wasn't aware of this type before, but I learnt something new today!

                http://speleotrove.com/decimal/

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #8

                  The OP does not say what environment is being used.

                  GCC optionally has some incomplete built-in support for decimal types in C++: http://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    movemove9
                    wrote on last edited by
                    #9

                    I have written a "blog":http://onethingor2.blogspot.tw/2014/05/decimal-for-qt-c.html which documented the use of qDecimal, here is the brief run-down.

                    http://onethingor2.blogspot.tw/2014/05/decimal-for-qt-c.html


                    Decimal for QT C++
                    We all know not to use primitive data type double for any arithmetic calculation involves financial or sensitive data which rounding errors is not acceptable. In that case, Java has java.math.BigDecimal, C# can use System.Decimal, but there is no Decimal built in support for C++.
                    However there are a few third party libraries to the rescue.

                    "GNU Multiple Precision Arithmetic Library.":https://gmplib.org/
                    "qdecimal":https://code.google.com/p/qdecimal/
                    "Intel's floating point math library":https://software.intel.com/en-us/articles/intel-decimal-floating-point-math-library/

                    We are going to focus on qdecimal, which specifically target QT C++ at this post.
                    Because I use Mingw-32 QT version, the library I download does not compile properly, so instead I include the source code into my project.

                    @#include <QCoreApplication>
                    #include <QtConcurrent/QtConcurrent>
                    #include "qdecimal/QDecDouble.hh"
                    #include "qdecimal/QDecNumber.hh"

                    int main(int argc, char *argv[])
                    {
                    QCoreApplication a(argc, argv);
                    QDecDouble decDouble = 10.00;
                    QDecDouble result = decDouble / 90;
                    QTextStream(stdout) << result.toString();
                    return a.exec();
                    }@

                    that's it, hop it helps.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      ckvsoft
                      wrote on last edited by
                      #10

                      HI
                      I know this is an old Topic but i found only this.

                      Your Example works, but when i use decDouble = 1.23 i got NaN as answer.
                      Any Ideas?

                      lg Chris

                      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