Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
talendstar
Creator
Creator

limit float to 2 places in tmap

I am using tmap to read data from a file and load it into a table.

 

One of the columns in the text file contains values like:

0.05

0.03

etc...

 

However when Talend flow uploads the data into the table the values change from 0.05 to 0.05000000075

or from 0.03 to 0.03999999911.

 

I have tried two approached in the tmap to try to reduce the value to two decimal places so I get only values like 0.05 or 0.03:

(row6.MinIncrease == null || row6.MinIncrease.equals("")) ? 0f :
row6.MinIncrease.floatValue()

 

(row6.MinIncrease == null || row6.MinIncrease.equals("")) ? 0f :
Math.round(row6.MinIncrease*100)/100f

 

but no luck. still getting values like 0.05000000075 .

 

What can I do here so I get only two decimal places?

 

thanks

Labels (2)
13 Replies
Anonymous
Not applicable

Hi,

 

    Did you try to add the precision part of your float column to 2?

0683p000009M5v6.png

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

talendstar
Creator
Creator
Author

Hello Nikhil,

 

I set the precision to 2 for the float data type. But that is not working for me. I am still seeing the same values.

 

Is there anything else I can do?

 

Thanks

Anonymous
Not applicable

Hi,

 

   Did you change the precision right from the schema of the input file or in between only from tMap?

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

talendstar
Creator
Creator
Author

Please have a look at the attached screenshots:

 

Here is the schema for text file:

0683p000009M60F.png

 

Here is the tmap:

0683p000009M5jt.png

One thing that I am doing in the tmap for this column is:

(row6.val == null || row6.val.equals("")) ? 0f :
Math.round(row6.val*100)/100f

 

 

thanks

talendstar
Creator
Creator
Author

I tried it on another float column and still no luck. 0683p000009MPcz.png

Anonymous
Not applicable

Hi,

 

    I am getting the data correctly for sample file.

0683p000009M60U.png

 

I tired to pass directly and also tried the function provided by you. But I did not get any issue.

0683p000009M60e.png

 

Personally, I would only go by null check for a float column like below and do not go for equal comparison with empty string.

 

Relational.ISNULL(row1.data)?0:row1.data 

But if you are still having issue, I might be missing something trivial here. Lets check with our Guru @rhall 

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

Anonymous
Not applicable

Can you remove your database component and simply print out your number value to the output window? Also, what database are you using? This looks like a floating point error. If it occurs during your Talend job (which you should see by outputting the value to the output window), the best way of dealing with this would be to use a BigDecimal instead of a float.

talendstar
Creator
Creator
Author

I am writing to Snowflake database.

 

Interestingly the source data file contains right value. For example:

0.05

 

But when written to Snowflake I get this:

0.05000000075

 

I will go ahead and try to use BigDecimal (I have not seen this working with Snowflake though).

 

 

Anonymous
Not applicable

Set the precision to 12 and just print to the output window. We need to know if this is a floating point issue caused during the processing of the number by Talend or after it is sent to Snowflake.