| | |
C++ Double - 8th point decimals
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi,
I have a problem that happens very rarely. I have a calculation which ads (for example) -15000.00 to 15575.51 and saves the results to an oracle database. However, the reslut in the databse is 575.51000002
Both figures are loaded elsewhere from the database and either have 0 or 2 decimals as in the example above.
The code processes millions of transactions, but less than .01 % has this error. Any ideas?
Thanks,
Shawn
I have a problem that happens very rarely. I have a calculation which ads (for example) -15000.00 to 15575.51 and saves the results to an oracle database. However, the reslut in the databse is 575.51000002
Both figures are loaded elsewhere from the database and either have 0 or 2 decimals as in the example above.
The code processes millions of transactions, but less than .01 % has this error. Any ideas?
Thanks,
Shawn
AddUpInputAK( int iIndexInputAK, int iAccumPos, int iAccumNeg, double* naSumsBW, double* naSumsRW ) {int iRet = SQC_C_Success; int iIndexSum; double nBetragBook; double nBetragBest; double nBetragKto; double nBetragRef; int iAK_Vorz; //// // //// if ( ALG_IsIntNull( iIndexInputAK ) ) {goto L_Eof;} if ( ALG_IsIntNull( iAccumPos ) && ALG_IsIntNull( iAccumNeg ) ) {goto L_Eof;} iIndexSum = 0; nBetragBook = m_naInpAbrKompBetrag[iIndexInputAK]; if ( ALG_IsDoubleNull( nBetragBook ) ) {goto L_Eof;} //// // Correct signage //// iAK_Vorz = 1; if ( m_saInpAbrKompVorz[iIndexInputAK].Left( 1 ) == "-" ) {iAK_Vorz = -1; nBetragBook = nBetragBook * ( -1.0);} if ( m_sPosArt == "KTO" ) { //// // Accounts //// if ( m_sKtoWhg == m_saInpAbrKompWhg[iIndexInputAK] ) {nBetragKto = m_naInpAbrKompBetrag[iIndexInputAK];if ( iAK_Vorz < 0 ) {nBetragKto = nBetragKto * ( -1 );} else {nBetragKto = nBetragBook;} ALG_SetDoubleNull( &nBetragKto ); } if ( ! ALG_IsDoubleNull( nBetragKto ) ) {naSumsBW[iIndexSum] = naSumsBW[iIndexSum] + nBetragKto;} } L_Eof: return( iRet ); }
>The code processes millions of transactions, but less than .01 % has this error. Any ideas?
That's a typical floating-point rounding fudge. If it's a serious enough problem, you can try to use a more precise type such as long double, or remove floating-point altogether to maintain exact precision. Though I suspect that an imprecision at the eighth decimal place isn't that much of an issue unless you're trying to do something with vanilla C++ types that shouldn't be done with vanilla C++ types. If that's the case, you really need to get a high precision mathematics library.
That's a typical floating-point rounding fudge. If it's a serious enough problem, you can try to use a more precise type such as long double, or remove floating-point altogether to maintain exact precision. Though I suspect that an imprecision at the eighth decimal place isn't that much of an issue unless you're trying to do something with vanilla C++ types that shouldn't be done with vanilla C++ types. If that's the case, you really need to get a high precision mathematics library.
I'm here to prove you wrong.
![]() |
Similar Threads
- Dictionary ADT (Computer Science)
- Point to Point3D Inheritance (C++)
- Is there an array[x][y][z] in C++ (i.e TRIPLE ARRAY)??? (C++)
- OOP any chance of assistance? Its about areas etc (C++)
Other Threads in the C++ Forum
- Previous Thread: really dont know what to do, c++?
- Next Thread: Assertion failure in loading
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






