OCCI rounding up higher value [message #673058] |
Sun, 04 November 2018 01:04 |
|
sinpeak
Messages: 59 Registered: January 2011 Location: india
|
Member |
|
|
Hi,
I am not sure if this is the right form to discuss my problem.
If not, please advise about the right forum to go to.
I have an OCCI code that selects a table column :
CREATE TABLE ETC ( MNY NUMBER(18,3) );
OCCI code has a double variable and it retrieves the above table column using a resultset and stores it in the double variable:
double dbMny;
stmt1 = conn->createStatement("select mny from ETC ");
rs = stmt1->getResultSet();
while (rs->next())
{
dbMny=rs->getDouble(1);
// Some processing logic //
}
This code works absolutely fine if MNY has lower values.
But I am facing problems with the highest possible value :-
Total 18 digits. 15 before decimal. 3 after decimal : 999999999999999.999
This value gets inserted fine in ETC table but when I retrieve it in my OCCI code it gets rounded to :-
1000000000000000000 (Total 19 digits)
and this is unacceptable to my client.
Am I doing something wrong ?
Please suggest/advise.
Thanks.
|
|
|
|
|
|
|
|
|
Re: OCCI rounding up higher value [message #673069 is a reply to message #673068] |
Sun, 04 November 2018 12:45 |
Solomon Yakobson
Messages: 3301 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
I thought I explained it. C++ offered FLOAT types use binary, Oracle NUMBER/FLOAT type uses decimal so when you converting decimal 999999999999999.999 to C++ binary float (double or not) you lose precision (same like you would in oracle as I showed in my example where I am casting decimal 999999999999999.999 to binary double). C++ language does not have decimal variables built into it, unlike other languages such as C#. I believe there are some C++ libraries for decimals offered by third party.
SY.
|
|
|
|
|
|
|
Re: OCCI rounding up higher value [message #673156 is a reply to message #673134] |
Fri, 09 November 2018 07:24 |
|
sinpeak
Messages: 59 Registered: January 2011 Location: india
|
Member |
|
|
Sure.
Here it is :
inline string num2Str(Number numVal) {
return (numVal.isNull()) ? "" : numVal.toText(env, "999999999999999999") ;
void function1
{
// declarations etc. go here
Number dbMny(0);
stmt1 = conn->createStatement("select mny from ETC ");
rs = stmt1->getResultSet();
while (rs->next())
{
dbMny =rs->getNumber(1);
// customPrint is another function used to print strings.
// I converted the number to string only because I was apprehensive that
// if I convert to integer/long/double then again it will round it like it used to before..
customPrint("MESSAGE_CODE_AXG7",(num2Str(dbMny)).c_str());
}
}
I did not get a chance to research on the best way to print Number in my code.
So instead of converting it into int/long/double and then printing it...I used .toText to convert to string and then print. It works fine.
I hope there is a way to print Number as it is without changing the value ( because of rounding ) and without converting to string.
If you know of any such way, then do let me know.
Thanks.
[Updated on: Fri, 09 November 2018 07:25] Report message to a moderator
|
|
|
|