Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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.
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.
Solved! thanks
Hi,
The logic works partially for me. Could you please help here?
Math.round(yourValueHere * 100.0)/100.0
I have the following values where I applied your logic:
215315.32499999998 results 215315.33 as expected
62644.37499999999 results 62644.37 I was expecting the result as 62644.38
Appreciate your help
Thanks,
BratB
Apologies..my question was is there a way we can achieve below in talend
215315.32499999998 results 215315.33 as expected
62644.37499999999 results 62644.37 I was expecting the result as 62644.38
Thanks,
Brat