One Star

[resolved] How to make float round to 2 decimal places in tMap?

Hi, I tried setting length to 5 and precision to 2 (just guessing), but that didn't affect my output number at all
I'm getting 6 decimal places now with no length or precision settings
Thanks Smiley Happy
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] How to make float round to 2 decimal places in tMap?

Try this one..... round a number to 2 decimal places
Mercal 
3 REPLIES
One Star

Re: [resolved] How to make float round to 2 decimal places in tMap?

Hello, ensure that your columns are BigDecimal types first. Then on the far side of a tMap or other component use something like:
input_row.column.scale(2,BigDecimal.ROUND_HALF_UP)

As an example, I put the following into a tJava to test it and got the results you're looking for:
BigDecimal bd = new BigDecimal(2.437732);
BigDecimal bd2 = bd.setScale(2,BigDecimal.ROUND_HALF_UP);
System.out.println("bd2 = "+bd2);

and it outputs:
Starting job test at 17:13 22/05/2014.
connecting to socket on port 3511
connected
bd2 = 2.44
disconnected
Job test ended at 17:13 22/05/2014.
One Star

Re: [resolved] How to make float round to 2 decimal places in tMap?

Thanks for that, this is a handy reference
For this Job...
... While originally testing with a CSV file, I have found that MySQL dealt with adequately it by making it a 'decimal' db data type and limiting the length to "5,2"
I will mark the thread "resolved" ? would mark it "double resolved" if I could! Smiley Happy
One Star

Re: [resolved] How to make float round to 2 decimal places in tMap?

Try this one..... round a number to 2 decimal places
Mercal