Double to varchar conversion

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Amar_nath
Participant
Posts: 56
Joined: Tue Apr 18, 2006 5:03 am

Double to varchar conversion

Post by Amar_nath »

Hello Folks,

I am trying read a double value from MS SQL server table and to write it in a CSV file on UNIX. For converting that double value I have used DFloatToStringNoExp() function.
I have defined the scale to maximum of the values in that attribute.
I am getting some extra digits (not always same) at the end of number ..

i.e.
e.g. input - 0.880899999884498
output of function is - 0.88089999988449819

data type of input column is Double(15) and output is varchar(100).

Please suggest how to get rid of extra added digits.

Thanks & Regards,
Amarnath
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What happens if you just allow an implicit conversion to occur?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Amar_nath
Participant
Posts: 56
Joined: Tue Apr 18, 2006 5:03 am

Post by Amar_nath »

When I write Double to Double it gives data in exponantial format. :(
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Double in, VarChar out, no conversion function. What happens then?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Amar_nath
Participant
Posts: 56
Joined: Tue Apr 18, 2006 5:03 am

Post by Amar_nath »

Double in, VarChar out, no conversion function. What happens then?
then also I get data in exponantial format
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It's a bit of a kluge, but the following will work. Stage variable svStringValue contains the raw result of the DFloatToStringNoExp() function.

Code: Select all

svStringValue <== DFloatToStringNoExp(InLink.TheDecimal)

Field(svStringValue, ".", 1, 1) : "." : Left(Field(svStringValue, ".", 2, 1), 15) 
If you know that the value is always between 0 and 1, you could go with

Code: Select all

Left(DFloatToStringNoExp(InLink.TheDecimal),17)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply