One Star

[resolved] From STRING or INTEGER to float with two decimals

Hello
We receive a delimited text file with one of the field that looks like this :"00000073142"
This field is an amount of money and should be read like 731.42
From this field I have to calculate another one which is 15% of it, here it would be 15% of 731.42 = 109.71
When I declare the discount (15%) field as a Float value, whenever 15% of whatever amount is a sum that end with a 0 (for exemple 31,90), it will be outputed as 31,9
That's not good because I want to print this field and need it to looks like a price, with two decimals.
How can I say inside a tMap component that a float value must have two decimals, no more no less.
I have tried the precision at two but it doesn't look like my answer.
Here and there, I have found the I could use some java code (decimalformat or math.round)
Problem is I don't know how the call this java code inside tMap. It seems I should create a routine than call it from tMap, but I don't know how to do this.
Is the any to do this ?
Thanks a lot
1 ACCEPTED SOLUTION

Accepted Solutions
Four Stars

Re: [resolved] From STRING or INTEGER to float with two decimals

Hi,
If you have few operations to be called on each row and column, then I would ask you to use tJavaRow before tMap and do processing as required...
Use Ctrl+Space, this will invoke all the existing functions and you can write your own with the help of Java code.
Thanks
vaibhav
2 REPLIES
Four Stars

Re: [resolved] From STRING or INTEGER to float with two decimals

Hi,
If you have few operations to be called on each row and column, then I would ask you to use tJavaRow before tMap and do processing as required...
Use Ctrl+Space, this will invoke all the existing functions and you can write your own with the help of Java code.
Thanks
vaibhav
One Star

Re: [resolved] From STRING or INTEGER to float with two decimals

Hi
Sorry for this late feedback, I had to fly away for some days...
Anyway, thanks a lot for your help.