Six 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.

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

Tags (1)

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.

Six Stars

Solved! thanks

All 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.

Six Stars

Solved! thanks

## What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

## Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch