Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
hgromek
Contributor
Contributor

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. 

0683p000009LuzR.jpg

 

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

 

Labels (2)
1 Solution

Accepted Solutions
cterenzi
Specialist
Specialist

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.

View solution in original post

4 Replies
cterenzi
Specialist
Specialist

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.

hgromek
Contributor
Contributor
Author

Solved! thanks 

Anonymous
Not applicable

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

 

Anonymous
Not applicable

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