One Star

convert string to double/float

Hi,
I got an issue where my source is delimiter file and it recognize a column as string in which it containing a value. I wants to convert from sting to double / float but it already rounded the value. I don't want it to be rounded. See example below:
INPUT
-------
0.00000215
0.00001645
After converting to double / float
OUTPUT
---------
0.000002
0.00002
EXPECTED OUTPUT
---------------------
0.00000215
0.00001645

Any idea? Please help me Smiley Sad
Regards,
Kal
6 REPLIES
Moderator

Re: convert string to double/float

Hi,
Could you use tConvertType to achieve your goal?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: convert string to double/float

Hi Sabrina,
I used exactly what you did. i got rounded decimal values. You can see the difference between VALUE_String and VALUE_Float as per below:

.------------+------------.
| tLogRow_1 |
|=-----------+-----------=|
|VALUE_string|VALUE_float |
|=-----------+-----------=|
|0.0000000000|0.0 |
|0.0000001000|0.0000001 |
|0.0000001000|0.0000001 |
|0.0000021500|0.000002 |
|0.0000021500|0.000002 |
|0.0000164500|0.00002 |
|0.0000164500|0.00002 |
|0.0000734000|0.00007 |
|0.0000734000|0.00007 |
|0.0004707000|0.0005 |
|0.0006008000|0.0006 |
|0.0006008000|0.0006 |
|0.0012983500|0.00129835 |
|0.0016000000|0.0016 |
|0.0024699000|0.0024699 |
|0.0039699000|0.0039699 |
|0.0054899000|0.0054899 |
|0.0067128000|0.0067128 |
|0.0087000000|0.0087 |
|0.0123961500|0.01239615 |
|0.0150000000|0.015 |
|0.0182337000|0.0182337 |
|0.0208000000|0.0208 |
|0.0225734000|0.0225734 |
|0.0251000000|0.0251 |
|0.0271793500|0.02717935 |
|0.0297519500|0.02975195 |
|0.0317519500|0.03175195 |
|0.0339575500|0.03395755 |
|0.0356000000|0.0356 |
I need to have the value exactly in float/double format since i wants to do some calculation. When the values already rounded then the end values of calculation will slightly inaccurate.
Smiley Sad
One Star

Re: convert string to double/float

use Double.parseDouble(text) in a tMap rule or Float.parseFloat(text)
One Star

Re: convert string to double/float

Hi Janhess,
To used that way, the same output returned.
Smiley Sad
Moderator

Re: convert string to double/float

Hi,
Could you please give us a screenshot of your workflow and the setting of your schema so that we can take a testing for your case.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: convert string to double/float

It's strange that only the first half of the results have been truncated.
Why don't you define the input as double in your input file schema.