Qt has No Decimal or Currency implement?
-
Hi,
C++ has the float and double types.
-
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?
-
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
-
-
[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!
-
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
-
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.