
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- « Previous Replies
-
- 1
- 2
- Next Replies »

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Did you try to add the precision part of your float column to 2?
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 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please have a look at the attached screenshots:
Here is the schema for text file:
Here is the tmap:
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried it on another float column and still no luck.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am getting the data correctly for sample file.
I tired to pass directly and also tried the function provided by you. But I did not get any issue.
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 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- « Previous Replies
-
- 1
- 2
- Next Replies »