Page 1 of 1

Double to varchar conversion

Posted: Thu Dec 23, 2010 2:57 am
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

Posted: Thu Dec 23, 2010 4:35 am
by ray.wurlod
What happens if you just allow an implicit conversion to occur?

Posted: Thu Dec 23, 2010 4:40 am
by Amar_nath
When I write Double to Double it gives data in exponantial format. :(

Posted: Thu Dec 23, 2010 4:42 am
by ray.wurlod
Double in, VarChar out, no conversion function. What happens then?

Posted: Thu Dec 23, 2010 5:41 am
by Amar_nath
Double in, VarChar out, no conversion function. What happens then?
then also I get data in exponantial format

Posted: Thu Dec 23, 2010 3:32 pm
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)