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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
RA6
Creator
Creator

Round value to two decimal place

Hello,

 

I have the following query which update a column :

 

UPDATE TABLE1 SET COLUMN1= CAST(COLUMN2 AS DECIMAL(15,2)) - CAST(COLUMN3 AS DECIMAL(15,2));

 

I want to apply the same thing in my tmap.

 

For info, column2 and column3 is of type string in my file.

 

COLUMN2 COLUMN3 EXPECTED RESULT
171 0  171.00
0 16 136.07    -16136.07
0 14 718.00    -14 718.00
0 296.61  -296.61
0 1 430.76    -1 430.76
46 040.94   0  46 040.94  

 

Can you advice please?

 

Thank you in advance.

 

Best regards,

asadasing

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

As column2 and column3 are Strings, you need to convert to Double before the operation, giving something like:

Double.parseDouble(row1.column2) - Double.parseDouble(row1.column3)

But, as you want 2 digits on the decimal part, you need to convert the result to String:

String.format("%.2f", (Double.parseDouble(row1.column2) - Double.parseDouble(row1.column3)))

Let me know if it works as expected.

 

 

View solution in original post

6 Replies
TRF
Champion II
Champion II

As column2 and column3 are Strings, you need to convert to Double before the operation, giving something like:

Double.parseDouble(row1.column2) - Double.parseDouble(row1.column3)

But, as you want 2 digits on the decimal part, you need to convert the result to String:

String.format("%.2f", (Double.parseDouble(row1.column2) - Double.parseDouble(row1.column3)))

Let me know if it works as expected.

 

 

manodwhb
Champion II
Champion II

@asadasing,can you try with Math.round() ?

RA6
Creator
Creator
Author

Hello TRF,

Thank you for your quick reasponse.
I checked in notepad++, It works but not in excel.

I guess in the next processing it will consider the decimals.

Best regards,
asadasing
TRF
Champion II
Champion II

OK.

Don't forget to mark your case as solved.

RA6
Creator
Creator
Author

Hello,

I have applied your solution and encountering some issue.

See url please : https://community.talend.com/t5/Design-and-Development/Format-value-to-two-decimal-places-without-ro...

Thank you.
Regards,
Asadasing
Anonymous
Not applicable

Hi,

what if i want to convert the values of float which is a string to an integer value.

Ex: My value is a string - 1.00000000, and i want to convert into Integer as 1.

 

I am trying the below expression, but not able to achieve the requirement.

Integer.parseInt(Double.parseDouble(row16.stringvalue)).IntValue() .

 

First converting the string to double and then converting to Integer.

 

Please suggest a solution, Thanks