dbTalk Databases Forums  

Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Fleetie
 
Posts: n/a

Default Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column - 05-21-2008 , 04:26 AM






Hi.

Forgive the news server I'm posting from; it's the only one I have easy
access to here at work, and it's a work-related problem.

Yesterday, we discovered that we are getting loss of precision, in the
form of truncation to 5 decimal places to the right of the point, when
INSERTing from a host variable in Pro*C that's declared as a C double.

It's a clean truncation/rounding to 5 decimal places, though the column
into which the INSERT is occurring is declared as NUMBER(16,6).

The numbers I'm trying to INSERT are unix-format times, with fractions
of a second down to microseconds, e.g.: 1211363748.425374.

So there are 16 decimal places to be stored in total, with 6 to the right
of the decimal place.

Yet when I SELECT the values back out of the table, I see all the values
rounded to 5 places to the right of the point.

HOWEVER, if I INSERT a double LITERAL value, all of the decimal places are
inserted correctly:

EXEC SQL INSERT INTO TESTPRECISION (KEY,VALUE)
VALUES
(
-1,
1234567890.123456
);

I then see the full 6 places to the right of the point, in the database.

Also, even if I increase the column width to accommodate more places in
total, e.g. to NUMBER(19,7), the INSERTS from the double host variable
are still rounded off at 5 places.

Then I tried converting the numbers to a string with:

sprintf(TVSTime,"%.6f",TVTime);

When I INSERT the string variable TVSTime into the NUMBER column, I get the
full
precision stored, presumably because Oracle performs the conversion and
INSERTs the converted values without loss of precision.

I'm at a loss to explain why INSERTing from a C double host variable only
stores 5 decimal places to the right of the point.

The version information is:

OS: SunOS solar 5.9 Generic_118558-06 sun4u sparc SUNW,Sun-Fire-V440
Oracle : Oracle Database 10g Release 10.1.0.2.0 - 64bit Production
Pro*C: Pro*C/C++: Release 10.1.0.2.0

Could it be anything to do with option native_types in Pro*C's pcscfg.cfg?

Thanks in advance for any help to resolve this.


Martin



Reply With Quote
  #2  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Varinto NUMBER(16,6) Column - 05-21-2008 , 07:29 AM






Don't...

Misuse data types, that is. You want date and or time info - store
in in an appropriate data type column; see Tom Kytes comment:

http://asktom.oracle.com/pls/asktom/...:1400155533292

--

Regards,
Frank van Bortel

Reply With Quote
  #3  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Varinto NUMBER(16,6) Column - 05-21-2008 , 07:29 AM



Don't...

Misuse data types, that is. You want date and or time info - store
in in an appropriate data type column; see Tom Kytes comment:

http://asktom.oracle.com/pls/asktom/...:1400155533292

--

Regards,
Frank van Bortel

Reply With Quote
  #4  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Varinto NUMBER(16,6) Column - 05-21-2008 , 07:29 AM



Don't...

Misuse data types, that is. You want date and or time info - store
in in an appropriate data type column; see Tom Kytes comment:

http://asktom.oracle.com/pls/asktom/...:1400155533292

--

Regards,
Frank van Bortel

Reply With Quote
  #5  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Varinto NUMBER(16,6) Column - 05-21-2008 , 07:29 AM



Don't...

Misuse data types, that is. You want date and or time info - store
in in an appropriate data type column; see Tom Kytes comment:

http://asktom.oracle.com/pls/asktom/...:1400155533292

--

Regards,
Frank van Bortel

Reply With Quote
  #6  
Old   
news.verizon.net
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column - 05-21-2008 , 09:19 AM




"Fleetie" <fleetie (AT) nospam (DOT) com> wrote

Quote:
Hi.

Forgive the news server I'm posting from; it's the only one I have easy
access to here at work, and it's a work-related problem.

Yesterday, we discovered that we are getting loss of precision, in the
form of truncation to 5 decimal places to the right of the point, when
INSERTing from a host variable in Pro*C that's declared as a C double.

It's a clean truncation/rounding to 5 decimal places, though the column
into which the INSERT is occurring is declared as NUMBER(16,6).

The numbers I'm trying to INSERT are unix-format times, with fractions
of a second down to microseconds, e.g.: 1211363748.425374.

So there are 16 decimal places to be stored in total, with 6 to the right
of the decimal place.

Yet when I SELECT the values back out of the table, I see all the values
rounded to 5 places to the right of the point.

HOWEVER, if I INSERT a double LITERAL value, all of the decimal places are
inserted correctly:

EXEC SQL INSERT INTO TESTPRECISION (KEY,VALUE)
VALUES
(
-1,
1234567890.123456
);

I then see the full 6 places to the right of the point, in the database.

Also, even if I increase the column width to accommodate more places in
total, e.g. to NUMBER(19,7), the INSERTS from the double host variable
are still rounded off at 5 places.

Then I tried converting the numbers to a string with:

sprintf(TVSTime,"%.6f",TVTime);

When I INSERT the string variable TVSTime into the NUMBER column, I get
the full
precision stored, presumably because Oracle performs the conversion and
INSERTs the converted values without loss of precision.

I'm at a loss to explain why INSERTing from a C double host variable only
stores 5 decimal places to the right of the point.

The version information is:

OS: SunOS solar 5.9 Generic_118558-06 sun4u sparc SUNW,Sun-Fire-V440
Oracle : Oracle Database 10g Release 10.1.0.2.0 - 64bit Production
Pro*C: Pro*C/C++: Release 10.1.0.2.0

Could it be anything to do with option native_types in Pro*C's pcscfg.cfg?

Thanks in advance for any help to resolve this.


Martin


Use timestamp datatype.
Jim




Reply With Quote
  #7  
Old   
news.verizon.net
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column - 05-21-2008 , 09:19 AM




"Fleetie" <fleetie (AT) nospam (DOT) com> wrote

Quote:
Hi.

Forgive the news server I'm posting from; it's the only one I have easy
access to here at work, and it's a work-related problem.

Yesterday, we discovered that we are getting loss of precision, in the
form of truncation to 5 decimal places to the right of the point, when
INSERTing from a host variable in Pro*C that's declared as a C double.

It's a clean truncation/rounding to 5 decimal places, though the column
into which the INSERT is occurring is declared as NUMBER(16,6).

The numbers I'm trying to INSERT are unix-format times, with fractions
of a second down to microseconds, e.g.: 1211363748.425374.

So there are 16 decimal places to be stored in total, with 6 to the right
of the decimal place.

Yet when I SELECT the values back out of the table, I see all the values
rounded to 5 places to the right of the point.

HOWEVER, if I INSERT a double LITERAL value, all of the decimal places are
inserted correctly:

EXEC SQL INSERT INTO TESTPRECISION (KEY,VALUE)
VALUES
(
-1,
1234567890.123456
);

I then see the full 6 places to the right of the point, in the database.

Also, even if I increase the column width to accommodate more places in
total, e.g. to NUMBER(19,7), the INSERTS from the double host variable
are still rounded off at 5 places.

Then I tried converting the numbers to a string with:

sprintf(TVSTime,"%.6f",TVTime);

When I INSERT the string variable TVSTime into the NUMBER column, I get
the full
precision stored, presumably because Oracle performs the conversion and
INSERTs the converted values without loss of precision.

I'm at a loss to explain why INSERTing from a C double host variable only
stores 5 decimal places to the right of the point.

The version information is:

OS: SunOS solar 5.9 Generic_118558-06 sun4u sparc SUNW,Sun-Fire-V440
Oracle : Oracle Database 10g Release 10.1.0.2.0 - 64bit Production
Pro*C: Pro*C/C++: Release 10.1.0.2.0

Could it be anything to do with option native_types in Pro*C's pcscfg.cfg?

Thanks in advance for any help to resolve this.


Martin


Use timestamp datatype.
Jim




Reply With Quote
  #8  
Old   
news.verizon.net
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column - 05-21-2008 , 09:19 AM




"Fleetie" <fleetie (AT) nospam (DOT) com> wrote

Quote:
Hi.

Forgive the news server I'm posting from; it's the only one I have easy
access to here at work, and it's a work-related problem.

Yesterday, we discovered that we are getting loss of precision, in the
form of truncation to 5 decimal places to the right of the point, when
INSERTing from a host variable in Pro*C that's declared as a C double.

It's a clean truncation/rounding to 5 decimal places, though the column
into which the INSERT is occurring is declared as NUMBER(16,6).

The numbers I'm trying to INSERT are unix-format times, with fractions
of a second down to microseconds, e.g.: 1211363748.425374.

So there are 16 decimal places to be stored in total, with 6 to the right
of the decimal place.

Yet when I SELECT the values back out of the table, I see all the values
rounded to 5 places to the right of the point.

HOWEVER, if I INSERT a double LITERAL value, all of the decimal places are
inserted correctly:

EXEC SQL INSERT INTO TESTPRECISION (KEY,VALUE)
VALUES
(
-1,
1234567890.123456
);

I then see the full 6 places to the right of the point, in the database.

Also, even if I increase the column width to accommodate more places in
total, e.g. to NUMBER(19,7), the INSERTS from the double host variable
are still rounded off at 5 places.

Then I tried converting the numbers to a string with:

sprintf(TVSTime,"%.6f",TVTime);

When I INSERT the string variable TVSTime into the NUMBER column, I get
the full
precision stored, presumably because Oracle performs the conversion and
INSERTs the converted values without loss of precision.

I'm at a loss to explain why INSERTing from a C double host variable only
stores 5 decimal places to the right of the point.

The version information is:

OS: SunOS solar 5.9 Generic_118558-06 sun4u sparc SUNW,Sun-Fire-V440
Oracle : Oracle Database 10g Release 10.1.0.2.0 - 64bit Production
Pro*C: Pro*C/C++: Release 10.1.0.2.0

Could it be anything to do with option native_types in Pro*C's pcscfg.cfg?

Thanks in advance for any help to resolve this.


Martin


Use timestamp datatype.
Jim




Reply With Quote
  #9  
Old   
news.verizon.net
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column - 05-21-2008 , 09:19 AM




"Fleetie" <fleetie (AT) nospam (DOT) com> wrote

Quote:
Hi.

Forgive the news server I'm posting from; it's the only one I have easy
access to here at work, and it's a work-related problem.

Yesterday, we discovered that we are getting loss of precision, in the
form of truncation to 5 decimal places to the right of the point, when
INSERTing from a host variable in Pro*C that's declared as a C double.

It's a clean truncation/rounding to 5 decimal places, though the column
into which the INSERT is occurring is declared as NUMBER(16,6).

The numbers I'm trying to INSERT are unix-format times, with fractions
of a second down to microseconds, e.g.: 1211363748.425374.

So there are 16 decimal places to be stored in total, with 6 to the right
of the decimal place.

Yet when I SELECT the values back out of the table, I see all the values
rounded to 5 places to the right of the point.

HOWEVER, if I INSERT a double LITERAL value, all of the decimal places are
inserted correctly:

EXEC SQL INSERT INTO TESTPRECISION (KEY,VALUE)
VALUES
(
-1,
1234567890.123456
);

I then see the full 6 places to the right of the point, in the database.

Also, even if I increase the column width to accommodate more places in
total, e.g. to NUMBER(19,7), the INSERTS from the double host variable
are still rounded off at 5 places.

Then I tried converting the numbers to a string with:

sprintf(TVSTime,"%.6f",TVTime);

When I INSERT the string variable TVSTime into the NUMBER column, I get
the full
precision stored, presumably because Oracle performs the conversion and
INSERTs the converted values without loss of precision.

I'm at a loss to explain why INSERTing from a C double host variable only
stores 5 decimal places to the right of the point.

The version information is:

OS: SunOS solar 5.9 Generic_118558-06 sun4u sparc SUNW,Sun-Fire-V440
Oracle : Oracle Database 10g Release 10.1.0.2.0 - 64bit Production
Pro*C: Pro*C/C++: Release 10.1.0.2.0

Could it be anything to do with option native_types in Pro*C's pcscfg.cfg?

Thanks in advance for any help to resolve this.


Martin


Use timestamp datatype.
Jim




Reply With Quote
  #10  
Old   
Fleetie
 
Posts: n/a

Default Re: Pro*C: Loss of Decimal Places INSERTing From "double" Host Var into NUMBER(16,6) Column - 05-21-2008 , 09:41 AM



Quote:
Use timestamp datatype.
Jim
Forgetting for now what the data is representing - pretend it's just a
number with 6 decimal places right of the point - I would still like to
know why my data is getting truncated.

I did not design this database I'm working on; it's >10 years old, and
I can't change it.

So anyone know why the truncation?


Thanks in advance,


Martin




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.