Float Type issue - C UDF

Database
Enthusiast

Float Type issue - C UDF

Incorrect output is displayed for FLOAT data type in C

 

 

 

memcpy(&(myDouble),tmpptr,myDataLen);
sprintf((tmpcoldata),"%f",myDouble);

 

 

myDouble = Double Data type

tmpptr = char* which holds actual data

myDataLen = no of Bytes for FLoat

 

I am using above code snipet to map Float Data type to C equivalent DOuble data type as both wll be 8 bytes of data.

In above I facing issue like the value  of precision if getting rounded of if its exceedss 6 digits.

 

Example :

Currently getting output :

Input                                      OutPut

3.45678787                       3.456788

 

But My ask is to have the value as such like in source table.

I tried with different format specifiers in c like %.15f , %g , %lf .... nothing worked.

 

Please give some idea to solve this issue.

 

 

 

  • float
  • float data type
  • Float Truncation
  • Float Type issue - C UDF
1 REPLY
Teradata Employee

Re: Float Type issue - C UDF

Did you try format %10.8f?  That should work.  E.g.,

sprintf("pi = %18.16f",4*atan2(1,1))  produces  "pi = 3.1415926535897931"

 

If you need greater precision try using the number data type (up to 38 digits), and cast it as character when retrieving it.