Qt has No Decimal or Currency implement?
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!!!
C++ has the float and double types.
JKSH, are you really what is Decimal or Currency type ???????
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.
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/
"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.
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
QDecDouble decDouble = 10.00;
QDecDouble result = decDouble / 90;
QTextStream(stdout) << result.toString();
that's it, hop it helps.
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.