Five Stars

Tmap Float variable needs to Round

This solution should be easy, however I can't seem to be able to figure it out. 

 

I need the result of a Float * int = float, to be rounded. 

talend.JPG

 

Please let me know of any solutions you can think of. 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Ten Stars

Re: Tmap Float variable needs to Round

Math.round() will round a float or a double to the nearest integer.  To round to two decimal places, you would use:

Math.round(yourValueHere * 100.0)/100.0

To round to an arbitrary decimal precision, you have to get a little fancier.  This stackoverflow article talks about how to implement rounding to arbitrary precision:

https://stackoverflow.com/questions/8911356/whats-the-best-practice-to-round-a-float-to-2-decimals

 

You could implement one of the solutions above in a routine in your repository, and just call that routine any time you need to round something.  If you don't foresee a frequent need to round values to arbitrary precision, I'd stick with an inline tMap formula.

Five Stars

Re: Tmap Float variable needs to Round

Solved! thanks 

2 REPLIES
Ten Stars

Re: Tmap Float variable needs to Round

Math.round() will round a float or a double to the nearest integer.  To round to two decimal places, you would use:

Math.round(yourValueHere * 100.0)/100.0

To round to an arbitrary decimal precision, you have to get a little fancier.  This stackoverflow article talks about how to implement rounding to arbitrary precision:

https://stackoverflow.com/questions/8911356/whats-the-best-practice-to-round-a-float-to-2-decimals

 

You could implement one of the solutions above in a routine in your repository, and just call that routine any time you need to round something.  If you don't foresee a frequent need to round values to arbitrary precision, I'd stick with an inline tMap formula.

Five Stars

Re: Tmap Float variable needs to Round

Solved! thanks